Skip to content

global/local syntax errors not caught #249

Open

Description

@pyflakes-bot

Original report by asmeurer (@asmeurer?) on Launchpad:


This is perhaps a bit obscure, but here's a class of syntax errors that aren't caught by pyflakes

$ cat test.py
def test(x):
    global x
$ pyflakes test.py
$ python test.py
  File "test.py", line 2
    global x
SyntaxError: name 'x' is parameter and global

I'm unsure what the full set of possible errors are here. One would need to check the Python source. I know there are some others relating to the Python 3 "nonlocal" keyword as well.

Activity

  1. asmeurer commented on Nov 4, 2017

    @asmeurer
    Contributor

    Just hit the nonlocal one. Would definitely be nice if pyflakes properly warned about these.

  2. asmeurer commented on Feb 8, 2019

    @asmeurer
    Contributor

    Another related one is nonlocal after a variable definition

    $ cat test2.py
    def test():
        a = 2
        nonlocal a
    $ python test2.py
      File "test2.py", line 3
        nonlocal a
        ^
    SyntaxError: name 'a' is assigned to before nonlocal declaration
    $ pyflakes test2.py # no errors
  3. vkrmjeet commented on Dec 1, 2021

    @vkrmjeet
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