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
{{ message }}
Repository navigation
[bug] AttributeError: 'alias' object has no attribute 'lineno' #15
I am getting this error when I try to run this command on a directory within Django with just a bunch of Python files with subdirectories.
>>> deadcode .
Traceback (most recent call last):
File "/Users/myuser/env3/bin/deadcode", line 8, in <module>
sys.exit(main())
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/cli.py", line 20, in main
unused_names = find_unused_names(filenames=filenames, args=args)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/actions/find_unused_names.py", line 13, in find_unused_names
dead_code_visitor.visit_abstract_syntax_trees()
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 106, in visit_abstract_syntax_trees
self.visit(node)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 503, in visit
self.visit(item)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 469, in visit
visitor(node)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 418, in visit_ImportFrom
self._add_aliases(node)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 187, in _add_aliases
self._define(
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/dead_code_visitor.py", line 259, in _define
first_lineno = lines.get_first_line_number(first_node)
File "/Users/myuser/env3/lib/python3.9/site-packages/deadcode/visitor/lines.py", line 82, in get_first_line_number
return node.lineno
AttributeError: 'alias' object has no attribute 'lineno'
changed the title [-]AttributeError: 'alias' object has no attribute 'lineno'[/-][+][bug] AttributeError: 'alias' object has no attribute 'lineno'[/+]on Jul 11, 2024
deadcode only works with python3.10+ at the moment, because lower Python versions have limited core ast package implementation.
I see two options, how it would be possible to deal with this issue:
ast implementation from higher Python versions could be extracted and backported to lower versions. But as I see it would require significant effort, since ast implementation is tightly coupled with C code
deadcode package could implement the missing ast features in the lower Python versions. However, this is not a priority until deadcode feature set becomes stable.
Activity
[-]AttributeError: 'alias' object has no attribute 'lineno'[/-][+][bug] AttributeError: 'alias' object has no attribute 'lineno'[/+]albertas commentedon Jul 11, 2024
deadcodeonly works with python3.10+ at the moment, because lower Python versions have limited coreastpackage implementation.I see two options, how it would be possible to deal with this issue:
astimplementation from higher Python versions could be extracted and backported to lower versions. But as I see it would require significant effort, sinceastimplementation is tightly coupled with C codedeadcodepackage could implement the missingastfeatures in the lower Python versions. However, this is not a priority untildeadcodefeature set becomes stable.