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 positive used-before-assignment on different line returns #4301

Closed
otchita opened this issue Apr 6, 2021 · 1 comment · Fixed by #4307
Closed

False positive used-before-assignment on different line returns #4301

otchita opened this issue Apr 6, 2021 · 1 comment · Fixed by #4307
Assignees
Labels
Assignment expression Related to the walrus operator / assignment expression False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@otchita
Copy link

otchita commented Apr 6, 2021

This is related to my previous issue #4238 for the support of the walrus operator. Another edge case seems to be unhandled. That of different line returns.

Steps to reproduce

Given a file good-test.py:

"""Good test example."""
def func():
    """Test."""
    return f'The number {(count := 4)} is equal to {count}'

pylint doesn't detect any errors which is expected. However when return to a line like this:

Given a file bad-test.py:

"""Bad test example."""
def func():
    """Test."""
    return f'The number {(count := 4)} ' \
           f'is equal to {count}'

We obtain the following:

Current behavior

Result of pylint bad-test.py:

************* Module test
bad-test.py:4:19: E0601: Using variable 'count' before assignment (used-before-assignment)

Expected behavior

Normally, this should not raise any errors.

pylint --version output

Result of pylint --version output on my local macOS:

pylint 2.7.4
astroid 2.5.2
Python 3.8.8 (v3.8.8:024d8058b0, Feb 19 2021, 08:48:17) 
[Clang 6.0 (clang-600.0.57)]
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Apr 6, 2021
@cdce8p cdce8p self-assigned this Apr 6, 2021
@cdce8p cdce8p added the Assignment expression Related to the walrus operator / assignment expression label Apr 6, 2021
@cdce8p
Copy link
Member

cdce8p commented Apr 6, 2021

Thanks for the report! The issue will be fixed with #4307

@cdce8p cdce8p added this to the 2.7.5 milestone Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assignment expression Related to the walrus operator / assignment expression False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants