You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's been a while I've experienced an issue when running pylint with pylint_django. I include the error traceback and the line I think causes the problem.
Traceback:
Traceback (most recent call last):
File "D:\DevTools\Python38-32\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\DevTools\Python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "D:\DevRepo\dex\venv\Scripts\pylint.exe\__main__.py", line 9, in <module>
File "d:\devrepo\dex\venv\lib\site-packages\pylint\__init__.py", line 22, in run_pylint
PylintRun(sys.argv[1:])
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\run.py", line 344, in __init__
linter.check(args)
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\pylinter.py", line 870, in check
self._check_files(
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\pylinter.py", line 904, in _check_files
self._check_file(get_ast, check_astroid_module, name, filepath, modname)
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\pylinter.py", line 930, in _check_file
check_astroid_module(ast_node)
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\pylinter.py", line 1062, in check_astroid_module
retval = self._check_astroid_module(
File "d:\devrepo\dex\venv\lib\site-packages\pylint\lint\pylinter.py", line 1107, in _check_astroid_module
walker.walk(ast_node)
File "d:\devrepo\dex\venv\lib\site-packages\pylint\utils\ast_walker.py", line 75, in walk
self.walk(child)
File "d:\devrepo\dex\venv\lib\site-packages\pylint\utils\ast_walker.py", line 72, in walk
callback(astroid)
File "d:\devrepo\dex\venv\lib\site-packages\pylint_django\checkers\forms.py", line 47, in visit_classdef
if child.targets[0].name == 'exclude':
AttributeError: 'Subscript' object has no attribute 'name'
After completely cleaned the file forms.py giving the error I think I've managed to isolate the problematic line. The file, still giving the error, now contains only this:
from django import forms
from dex import models
class DataSelectionForm(forms.ModelForm):
"""
Form
"""
class Meta:
model = models.DataSelection
fields = [
"field",
]
widgets = {}
widgets["field"] = forms.CheckboxSelectMultiple
Of course, I've overly simplified that form class. It seems the error is caused by widgets["field"] = forms.CheckboxSelectMultiple, which in the real code is adding a different widget to a specific field after a loop creates the widgets dict.
If I use instead widgets = {"field": forms.CheckboxSelectMultiple} then everything is fine.
After digging into pylint_django's code I've found the following:
meta.get_children() returns all children of the Meta class, which in the sample code contains a dictionary assignment.
The expected children are of type Assign whose first item in the attribute targets is of type AssignName, like AssignName.widgets(name='widgets').
An instruction like widget["field"] = forms.SomeWidget will result in a Assign child containing a Subscript(ctx=<Context.Store: 2>, value=<Name.widgets ...>, slice=<Index ...>). This is of course unexpected.
I'll submit a PR fixing that, if that's fine for you. I guess other unexpected instructions in the Meta class can trigger similar errors, so probably the most economic solution is to enclose the code in try... except and ignore the AttributeError. Trying to identify the type of object before accessing the name attribute would probably incur in a slower execution.
Dear all,
It's been a while I've experienced an issue when running
pylint
withpylint_django
. I include the error traceback and the line I think causes the problem.Traceback:
After completely cleaned the file
forms.py
giving the error I think I've managed to isolate the problematic line. The file, still giving the error, now contains only this:Of course, I've overly simplified that form class. It seems the error is caused by
widgets["field"] = forms.CheckboxSelectMultiple
, which in the real code is adding a different widget to a specific field after a loop creates thewidgets
dict.If I use instead
widgets = {"field": forms.CheckboxSelectMultiple}
then everything is fine.A few details about my configuration:
Result of
pip freeze
:Thank you for your time!
The text was updated successfully, but these errors were encountered: