Skip to content

F821 for builtins? #118

Closed
Closed

Description

@asottile

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?

Activity

  1. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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
    
  2. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

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

    In the future, please ask your question on StackOverflow.

  3. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

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

    @przemyslaw-hejman

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

  4. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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.

  5. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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?

  6. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions