PyCQA / pyflakes

A simple program which checks Python source files for errors
https://pypi.org/project/pyflakes
MIT License
1.37k stars 178 forks source link

Internal error on `__all__, = ...` #674

Closed decorator-factory closed 2 years ago

decorator-factory commented 2 years ago

Steps to reproduce:

  1. Install pyflakes==2.4.0
  2. Create a file with the name of foo.py
  3. Place the following in the file (the comma after __all__ is intentional):
    __all__, = (
    "fizz",
    "buzz",
    )
  4. Run pyflakes foo.py

Outcome:

Traceback (most recent call last):
  File "/tmp/foo/venv/bin/pyflakes", line 8, in <module>
    sys.exit(main())
...
  File "/tmp/foo/venv/lib/python3.9/site-packages/pyflakes/checker.py", line 591, in __init__
    if isinstance(source.value, (ast.List, ast.Tuple)):
AttributeError: 'Tuple' object has no attribute 'value'

After a bit of investigation, this method assumes that source is a ast.Name. But in reality it can be ast.Tuple or some other more complicated target.

I think the right behaviour is to mark this as invalid to the user.

I'd be happy to work on this issue myself.

sigmavirus24 commented 2 years ago

Why do you want to use use __all__, = ...?

decorator-factory commented 2 years ago

I definitely don't want to use it :) I found this when running flake8 on some piece of code which had this, as a typo perhaps But I don't think pyflakes should crash on this