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

False negative | No binding for nonlocal found #6883

Closed
mbyrnepr2 opened this issue Jun 6, 2022 · 5 comments · Fixed by #7099
Closed

False negative | No binding for nonlocal found #6883

mbyrnepr2 opened this issue Jun 6, 2022 · 5 comments · Fixed by #7099
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code
Milestone

Comments

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Jun 6, 2022

def outer():
  nonlocal a
  a = 1
outer()
  • pylint gives a success
  • but if you comment out a = 1 pylint also finds the missing binding

Originally posted by @da-dada in #6812 (comment)

Further information:

python example.py
  File "/Users/markbyrne/programming/example.py", line 2
    nonlocal a
    ^^^^^^^^^^
SyntaxError: no binding for nonlocal 'a' found
@mbyrnepr2
Copy link
Member Author

Created this as I thought this would deserve its own issue since it was not the original subject of #6812

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative 🦋 No message is emitted but something is wrong with the code label Jun 6, 2022
@da-dada
Copy link

da-dada commented Jun 7, 2022

there is a somewhat similar behaviour with global

A = 1
class Foo:
    global A
    A = 2

print(Foo.A)

I beg your pardon if I have entered this comment the wrong way again, but I simply don't find a template or anything like it you have been mentioning

@mbyrnepr2
Copy link
Member Author

@da-dada
Copy link

da-dada commented Jun 8, 2022

@mbyrnepr2 I'll give it a try

@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Jun 9, 2022
@mbyrnepr2
Copy link
Member Author

Created #7098 so that the current issue can stay focused on the original nonlocal issue.

mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue Jun 30, 2022
It was not emitted when the `nonlocal` name is assigned later on in the same scope.

Closes pylint-dev#6883
@mbyrnepr2 mbyrnepr2 changed the title No binding for nonlocal found False negative | No binding for nonlocal found Jun 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.0 milestone Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants