Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadowing and unshadowing a builtin makes pyflakes emit a F821 #548

Open
mgedmin opened this issue May 25, 2020 · 0 comments
Open

Shadowing and unshadowing a builtin makes pyflakes emit a F821 #548

mgedmin opened this issue May 25, 2020 · 0 comments

Comments

@mgedmin
Copy link
Contributor

mgedmin commented May 25, 2020

Consider this silly code:

int = 42
del int

x = int('42')
print(x)

This is perfectly valid Python: if you run it, it'll print 42.

flake8 emits a F821: undefined name 'int' on the penultimate line. I think it's because of the del int.

For a real-world example of this situation, consider a project that uses gettext and installs _ in builtins, but doesn't do that early enough to be available at import time of every module. Here's how linkchecker copes with that situation:

_ = lambda x: x
Fields = dict(
    realurl=_("Real URL"),
    cachekey=_("Cache key"),
...
    level=_("Level"),
    modified=_("Modified"),
)
del _

and this then causes flake8 to complain about _() being used elsewhere in the file:

./linkcheck/logger/__init__.py:278:19: F821 undefined name '_'
./linkcheck/logger/__init__.py:340:16: F821 undefined name '_'
./linkcheck/logger/__init__.py:377:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:380:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:382:22: F821 undefined name '_'
./linkcheck/logger/__init__.py:390:22: F821 undefined name '_'

flake8 --version reports

3.8.2 (flake8_2020: 1.6.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes: 2.2.0) CPython 3.8.2 on Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant