Skip to content

F821 undefined name gives wrong line number (alwasy line 1) when variable is in an f-string #562

Closed

Description

@asottile

In GitLab by @samuelcolvin on Feb 22, 2017, 06:07

setup:

➤  flake8 --bug-report
{
  "dependencies": [
    {
      "dependency": "setuptools",
      "version": "34.2.0"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.6.0+",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.3.1"
    },
    {
      "plugin": "pyflakes",
      "version": "1.5.0"
    }
  ],
  "version": "3.3.0"
}

foobar.py:

a = 'this is a test'
b = f'this is a good fstring: {a}'
c = f'this is a bad fstring: {abc}'
➤  flake8 foobar.py 
foobar.py:1:2: F821 undefined name 'abc'

You would expect the error to say line 3 not line 1.

Activity

  1. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @samuelcolvin on Feb 22, 2017, 06:10

    sorry, realised this should have been posted to pyflakes.

  2. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @samuelcolvin on Feb 22, 2017, 06:10

    closed

  3. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @samuelcolvin on Feb 22, 2017, 06:18

    Error in pyflakes it slightly different, I'm now a bit confused about whether this should be posted here or on the pyflakes' launchpad.

    I'll leave it open here, let me know if you want me to close here and resubmit elsewhere.

  4. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @samuelcolvin on Feb 22, 2017, 06:18

    reopened

  5. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @sigmavirus24 on Feb 22, 2017, 06:27

    So https://bugs.launchpad.net/pyflakes/+bug/1666811 was reported this morning. PyFlakes doesn't report columns so the error may be slightly dissimilar. That said, this is definitely a bug in pyflakes.

  6. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @samuelcolvin on Feb 22, 2017, 06:29

    Thanks, sorry for missing that. I'm guessing you want the issue left open until it's fixed upstream?

  7. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @blueyed on Feb 15, 2018, 16:18

    According to https://bugs.launchpad.net/pyflakes/+bug/1666811/comments/3 this is fixed/improved with Python 3.6.3.

  8. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor
  9. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @sigmavirus24 on Oct 20, 2018, 10:17

    closed

  10. asottile commented on Apr 3, 2021

    @asottile
    MemberAuthor

    In GitLab by @asottile on Oct 2, 2020, 16:37

    changed the description

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