I was doing some analysis about the Coronavirus and PyLint detect some undefined variables that are defined in an if statement or by a with statement. my code work as expected and is see no errors or runtime warnings. Here's my code :
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime,date
import os
import requests
import numpy as np
class Covid:
filename = 'data/' + str(date.today()) + '.csv'
if not os.path.exists(filename):
res = requests.get("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv")
with open(filename, 'w') as f:
f.write(res.content.decode( "ISO-8859-1"))
dateparse = lambda x: pd.datetime.strptime(x, '%d/%m/%Y')
df = pd.read_csv(filename,sep=',', parse_dates=['dateRep'], date_parser=dateparse, encoding= "ISO-8859-1")
the __init__
and the other functions of the class are after this.
My problem is that PyLint show me warnings about undefined variables:
the f
at line 12, just after the as
, where it's defined,
the f
at line 13,
the res
at line 13 (this warning disappear if i define res
outside of the if statement).
It's not a major issue since my program still run but I'd like to understand why does PyLint shows me theses warnings and to get rid of theses warnings. They don't appear if I do all of this outside the class definition.
Am I doing something wrong ? Is it PyLint that not do what it is supposed to do ?
I am working with Visual Studio Code, pylint 2.4.4 astroid 2.3.3 and Python 3.8.2