Skip to content

Spurious F841 in exception even when referenced by locals() #376

Description

@jaraco

I recently upgraded to flake8 3.6 and pyflakes 2.0.0, and now I'm getting failures in code where locals() contains the only reference to a variable in the namespace.

draft $ cat > f841fail.py
try:
    raise ValueError()
except Exception as e:
    print(locals())
draft $ python f841fail.py
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x10138c710>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'f841fail.py', '__cached__': None, 'e': ValueError()}
draft $ flake8 --version
3.6.0 (mccabe: 0.6.1, pycodestyle: 2.4.0, pyflakes: 2.0.0) CPython 3.7.1 on Darwin
draft $ flake8 f841fail.py
f841fail.py:3:1: F841 local variable 'e' is assigned to but never used
draft $ pip install -U pyflakes
Requirement already up-to-date: pyflakes in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.0.0)

In other blocks, the use of locals() prevents F841 from being triggered. It should in exception blocks too.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions