JBKahn / flake8-print

flake8
MIT License
121 stars 21 forks source link

Tuple parameter unpacking makes flake8-print fail #31

Closed wojcikstefan closed 2 years ago

wojcikstefan commented 6 years ago

Steps to reproduce

  1. Create a test.py file with the following contents:
    def fail((a, b, c)):
    pass
  2. Run flake8 test.py (with flake8-print installed).

Expected: flake8 run passes without raising any issues. Actual: flake8 fails with the following traceback:

(venv) [test_flake8_print] flake8 test.py
Traceback (most recent call last):
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 384, in _run
    self.run_checks()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 310, in run_checks
    self.file_checker_manager.run()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/checker.py", line 319, in run
    self.run_parallel()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/checker.py", line 288, in run_parallel
    for ret in pool_map:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 668, in next
    raise value
AttributeError: 'Tuple' object has no attribute 'id'

Reason

I traced the problem back to this line: https://github.com/JBKahn/flake8-print/blob/e5d3812c4c93628ed804e9ecf74c2d31780627e5/flake8_print.py#L50

When the function definition contains a tuple parameter one of the args is an _ast.Tuple object, not the expected _ast.Name. _ast.Tuple doesn't have the id attribute, hence arg.id raises the AttributeError seen in the traceback.

Note that tuple parameter unpacking has been removed in Python 3 via PEP 3113, so this is only a bug in handling Python 2 files.

JBKahn commented 2 years ago

Since this is only for python 2 files (and I didn't see this issue for forever) it seems like not worth fixing now that this library is python 3 only.