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

Regression: used-before-assignment error not reported for function arguments #2374

Closed
pbasista opened this issue Aug 1, 2018 · 1 comment · Fixed by #7408
Closed

Regression: used-before-assignment error not reported for function arguments #2374

pbasista opened this issue Aug 1, 2018 · 1 comment · Fixed by #7408
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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation Regression
Milestone

Comments

@pbasista
Copy link

pbasista commented Aug 1, 2018

Steps to reproduce

Run Pylint on the following code:

"""A module to demonstrate Python's UnboundLocalError exception."""

def test(tmp=0):
    """Demonstrate UnboundLocalError exception on a function argument."""
    print(tmp)
    def inner():
        """Python considers "tmp" as a local variable in this function."""
        print(tmp)  # UnboundLocalError is raised here
        tmp = 1
    inner()
    print(tmp)


test()

Current behavior:

No warning or error is reported.

However, the code fails to run because of this well-known issue with using variables considered as local before their assignment. The following exception is raised:

UnboundLocalError: local variable 'tmp' referenced before assignment

Expected behavior

used-before-assignment error is reported on line where tmp is first used in function inner.

This error is correctly reported by Pylint 1.9.3, but not by Pylint versions 2 and above.

A similar error is correctly reported by Pylint versions 2 and above when the tmp variable is locally defined within the outer function, but not when it is a function's argument.

pylint --version output

pylint 2.1.0
astroid 2.0.2
Python 3.6.6 (default, Jun 27 2018, 14:44:17)
[GCC 8.1.0]
(the current master branch version 7be00a9)

@pbasista pbasista changed the title used-before-assignment warning not reported for function arguments used-before-assignment error not reported for function arguments Aug 1, 2018
@PCManticore
Copy link
Contributor

Thanks for the report, I can also reproduce this regression.

@PCManticore PCManticore modified the milestones: Next bug fix release, Next minor release Aug 8, 2018
@PCManticore PCManticore changed the title used-before-assignment error not reported for function arguments Regression: used-before-assignment error not reported for function arguments Aug 8, 2018
@PCManticore PCManticore removed this from the Next minor release milestone Sep 23, 2018
@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Mar 31, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Bug 🪲 labels Jul 13, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.16.0 milestone Sep 4, 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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation Regression
Projects
None yet
4 participants