I'm using VSCode and the Pylint that ships with it, i.e., no extension. Everything has been running smooth for many months and I've never had an issue with Pylint presenting weird alerts.
I recently started learning Django and today when following the official Django Documentation tutorial part 4 pylint could not recognize a couple of statements related to a model.
selected_choice = question.choice_set.get(pk=request.POST['choice'])
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
The errors I get from pylint are below
choice_set: Unknown
Cannot access member "choice_set" for type "Question"
Member "choice_set" is unknownPylancereportGeneralTypeIssues
and
id: Unknown
Cannot access member "id" for type "Question"
Member "id" is unknownPylancereportGeneralTypeIssues
At first I thought the issue might've been I'd forgot to cross reference the Question and Choice models, but this is not the case. For reference, here are the related files for the project
I can run the project without errors.
To momentarily solve this problem I just told pylint to ignore this, but I don't fell this best practice. Maybe I'm missing something here?
below the code I ended up writing for these two lines. Any hints?
#(...)
selected_choice = question.choice_set.get(pk=request.POST['choice']) #type: ignore
#(...)
return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) #type: ignore
Solution in trial:
nothing changed.
You can use command pip install pylint-django
to install pylint-django
and add the following codes to your settings.json
:
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
]