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

Problem with nonlocal written only falsely reported as unused. #3044

Closed
kayhayen opened this issue Aug 4, 2019 · 2 comments · Fixed by #7537
Closed

Problem with nonlocal written only falsely reported as unused. #3044

kayhayen opened this issue Aug 4, 2019 · 2 comments · Fixed by #7537
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Minor 💅 Polishing pylint is always nice Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@kayhayen
Copy link

kayhayen commented Aug 4, 2019

Steps to reproduce

The above code in a Nuitka test gives a warning:

def simpleFunction4():
    a = 1

    def nonlocal_writer():
        nonlocal a

        for a in range(10): 
            pass

    nonlocal_writer()

    assert a == 9, a

Current behavior

I need to put # false alarm, pylint: disable=unused-variable in the loop.

Expected behavior

Since the nonlocal value is being read, it shouldn't be considered unused.

pylint --version output

$ /c/Python37/python -m pylint --version
main.py 2.3.1
astroid 2.2.5
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]

@PCManticore
Copy link
Contributor

Thanks @kayhayen for the report. This looks like a slight edge case though as you're relying on the side effect of iteration to set the a variable in the outer scope. Still a bug though.

@kayhayen
Copy link
Author

kayhayen commented Aug 6, 2019

It's from a Nuitka test, I don't think it deserves very much priority, but I think there is something flawed then, a potential write, still is a write, right?

@hippo91 hippo91 self-assigned this Sep 8, 2019
@Pierre-Sassoulas Pierre-Sassoulas added Minor 💅 Polishing pylint is always nice False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jun 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Jun 30, 2022
clavedeluna added a commit to clavedeluna/pylint that referenced this issue Sep 27, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.4 milestone Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Minor 💅 Polishing pylint is always nice Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants