Skip to content
New issue

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

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

Already on GitHub? # to your account

F821 for builtins? #118

Closed
asottile opened this issue Apr 3, 2021 · 6 comments
Closed

F821 for builtins? #118

asottile opened this issue Apr 3, 2021 · 6 comments

Comments

@asottile
Copy link
Member

asottile commented Apr 3, 2021

In GitLab by @przemyslaw-hejman on Jul 17, 2015, 01:14

Hey, I've recently cracked into such an issue:

./base/tests/test_graphite.py:78:44: F821 undefined name 'ConnectionRefusedError'

Of course I did not import that explicitly as these are builtins: https://docs.python.org/3/library/exceptions.html

Using flake8==2.4.1

For now solving that with tox config:

[flake8]
ignore = F821

but i think this error should also consider builtins - or maybe it does and I'm doing something wrong?

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jul 17, 2015, 05:53

Are you running Flake8 on Python 2 against Python 3 code? If so, install Flake8 on Python 3, remove that ignore line, and then re-run it. The problem should disappear.

If you can't run it on Python 3, try out the --builtins flag. From flake8 -h:

  --builtins=BUILTINS   define more built-ins, comma separated

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jul 17, 2015, 05:54

In the future, please ask your question on StackOverflow.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jul 18, 2015, 18:45

@przemyslaw-hejman

Do you need anything else from this or can this be closed?

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @przemyslaw-hejman on Jul 20, 2015, 06:00

Hey Ian,

Thanks for your assistance here! I was running flake8 on python3 against python3... Anyway, --builtins works for me well. Feel free to close this issue.

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jul 20, 2015, 07:58

@przemyslaw-hejman it's important that if you're writing code for Python 3.4 to be running Flake8 under Python 3.4 (for example). The builtins shouldn't change drastically between versions, but Python 3 is a rapidly evolving language. That said, ConnectionRefusedError looks to have been made a built-in type in Python 3.3. If you're running Flake8 on an earlier version of Python (3.2 or 3.1 for example) it is rightfully complaining that ConnectionRefusedError is not defined.

Can you confirm that flake8 is running against the same version of python you're using? Not just Python3?

@asottile
Copy link
Member Author

asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Jul 20, 2015, 08:02

For what it's worth, I cannot verify this:

(test-flake8-py33)~/test-flake8-py33$ cat test.py
try:
    0/0
except ConnectionRefusedError:
    pass
except ZeroDivisionError:
    pass
(test-flake8-py33)~/test-flake8-py33$ flake8 --version
2.4.1 (pep8: 1.5.7, pyflakes: 0.8.1, mccabe: 0.3.1) CPython 3.3.6 on Linux
(test-flake8-py33)~/test-flake8-py33$ flake8 test.py
(test-flake8-py33)~/test-flake8-py33$ echo $?
0

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant