Tadaboody / good_smell

A linting/refactoring library for python best practices and lesser-known tricks
BSD 3-Clause "New" or "Revised" License
30 stars 3 forks source link

Tuple object has no attribute id #61

Closed Dreamsorcerer closed 3 years ago

Dreamsorcerer commented 5 years ago

When running good_smell on a project, I get this error:

Traceback (most recent call last):
  File "/usr/local/bin/flake8", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.7/site-packages/flake8/main/cli.py", line 18, in main
    app.run(argv)
  File "/usr/local/lib/python3.7/site-packages/flake8/main/application.py", line 394, in run
    self._run(argv)
  File "/usr/local/lib/python3.7/site-packages/flake8/main/application.py", line 382, in _run
    self.run_checks()
  File "/usr/local/lib/python3.7/site-packages/flake8/main/application.py", line 301, in run_checks
    self.file_checker_manager.run()
  File "/usr/local/lib/python3.7/site-packages/flake8/checker.py", line 330, in run
    self.run_serial()
  File "/usr/local/lib/python3.7/site-packages/flake8/checker.py", line 314, in run_serial
    checker.run_checks()
  File "/usr/local/lib/python3.7/site-packages/flake8/checker.py", line 608, in run_checks
    self.run_ast_checks()
  File "/usr/local/lib/python3.7/site-packages/flake8/checker.py", line 504, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/usr/local/lib/python3.7/site-packages/good_smell/flake8_ext.py", line 20, in run
    warnings = smell(tree=self.tree, path=self.filename).check_for_smell()
  File "/usr/local/lib/python3.7/site-packages/good_smell/ast_smell.py", line 29, in check_for_smell
    transformer.visit(self.tree)
  File "/usr/local/lib/python3.7/site-packages/good_smell/ast_smell.py", line 20, in visit
    return self.generic_visit(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 317, in generic_visit
    value = self.visit(value)
  File "/usr/local/lib/python3.7/site-packages/good_smell/ast_smell.py", line 20, in visit
    return self.generic_visit(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 317, in generic_visit
    value = self.visit(value)
  File "/usr/local/lib/python3.7/site-packages/good_smell/ast_smell.py", line 22, in visit
    return super().visit(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 262, in visit
    return visitor(node)
  File "/usr/local/lib/python3.7/site-packages/good_smell/smells/filter.py", line 42, in visit_For
    node.iter, node.target, gen_target)
  File "/usr/local/lib/python3.7/site-packages/good_smell/smells/filter.py", line 24, in replace_name_with_node
    return NameReplacer(old_val, new_val).visit(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 262, in visit
    return visitor(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 326, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 262, in visit
    return visitor(node)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 326, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 262, in visit
    return visitor(node)
  File "/usr/local/lib/python3.7/site-packages/good_smell/smells/filter.py", line 14, in visit_Name
    if node.id == self.old.id:
AttributeError: 'Tuple' object has no attribute ‘id'
Dreamsorcerer commented 4 years ago

I think I've narrowed this down to unpacking in a for loop such as: for inst, aliases in updates:

Error still occurs in 0.17.