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

No used-before-assignment for use of nested function before its definition #6812

Closed
da-dada opened this issue Jun 2, 2022 · 2 comments · Fixed by #6959
Closed

No used-before-assignment for use of nested function before its definition #6812

da-dada opened this issue Jun 2, 2022 · 2 comments · Fixed by #6959
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

Comments

@da-dada
Copy link

da-dada commented Jun 2, 2022

Bug description

def outer():
    inner()
    def inner():
        pass

outer()

Should raise used-before-assignment on use of inner() but doesn't.

Configuration

No response

Command used

@echo off
rem see https://wiki.geany.org/howtos/check_python_code
set PYTHONPATH=%PYTHONPATH%;C:\Users\Me\Documents\Programming\Python\Mylib\My
rem set PYTHONPATH
set configfile=C:\Users\Me\Documents\Programming\Geany\BuildCommands\Python3\pylintrc
rem C:\Users\Me\AppData\Local\Programs\Python\Python38\Scripts\pylint --version
echo Using configfile %configfile%
echo   [without C0111(missing-docstring), C0103(invalid-name), W0201(attribute-defined-outside-init), W0703(broad-except), R1710(inconsistent-return-statements)
echo   generated-members=wx, additional-builtins=App, Envi; overgeneral-exceptions=None]
C:\Users\Me\AppData\Local\Programs\Python\Python39\Scripts\pylint --rcfile=%configfile% --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" %1
rem C:\Users\Me\AppData\Local\Programs\Python\Python39\Scripts\pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" %1

Pylint output

Using configfile C:\Users\Me\Documents\Programming\Geany\BuildCommands\Python3\pylintrc
  [without C0111(missing-docstring), C0103(invalid-name), W0201(attribute-defined-outside-init), W0703(broad-except), R1710(inconsistent-return-statements)
  generated-members=wx, additional-builtins=App, Envi; overgeneral-exceptions=None]
************* Module pylint_error
pylint_error.py:1: [C0104(disallowed-name), foo] Disallowed name "foo"
pylint_error.py:2: [C0321(multiple-statements), foo] More than one statement on a single line
Compilation finished successfully.

Expected behavior

expected used-before-assignment

Pylint version

pylint 2.12.2
astroid 2.9.3
Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)]

OS / Environment

Edition Windows 10 Home
Version 21H1
Installed on ‎21.‎08.‎2020
OS build 19043.1706
Experience Windows Feature Experience Pack 120.2212.4170.0

Additional dependencies

No response

@da-dada da-dada added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 2, 2022
@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code C: used-before-assignment Issues related to 'used-before-assignment' check and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 2, 2022
@jacobtylerwalls
Copy link
Member

Very similar to #4624, and should probably be addressed at the same time.

@jacobtylerwalls jacobtylerwalls added False Negative 🦋 No message is emitted but something is wrong with the code and removed False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jun 2, 2022
@jacobtylerwalls jacobtylerwalls changed the title local variable muddle No used-before-assignment for use of nested function before its definition Jun 2, 2022
@da-dada
Copy link
Author

da-dada commented Jun 3, 2022

whilst you are at it, using nonlocal like this always dumps with SyntaxError

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

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.

2 participants