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

used-before-assignment false positive for import nodes under elif after TYPE_CHECKING #8437

Closed
jacobtylerwalls opened this issue Mar 11, 2023 · 2 comments · Fixed by #8441, #8521 or #9093
Closed
Assignees
Labels
C: used-before-assignment Issues related to 'used-before-assignment' check 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
Milestone

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Mar 11, 2023

Bug description

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    pass
elif 42:
    import math


print(math)

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:5:5: W0125: Using a conditional statement with a constant value (using-constant-test)
a.py:9:6: E0601: Using variable 'math' before assignment (used-before-assignment)

--------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 10.00/10, -10.00)

Expected behavior

************* Module a
a.py:5:5: W0125: Using a conditional statement with a constant value (using-constant-test)

--------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 10.00/10, -10.00)

Pylint version

pylint 3.0.0a6
astroid 2.16.0dev0
Python 3.11.0

OS / Environment

No response

Additional dependencies

No response

@jacobtylerwalls jacobtylerwalls added C: used-before-assignment Issues related to 'used-before-assignment' check Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Mar 11, 2023
@jacobtylerwalls jacobtylerwalls added this to the 2.17.1 milestone Mar 11, 2023
@jacobtylerwalls jacobtylerwalls added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Mar 11, 2023
@jacobtylerwalls
Copy link
Member Author

@zenlyj tagging you so you're aware of the issue while developing; this is the sort of thing we could merge quickly and backport to 2.17.x, if you're interested in contributing a fix.

@zenlyj
Copy link
Contributor

zenlyj commented Mar 12, 2023

thanks for creating this issue! I would like to work on this one, please assign it to me.

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 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
Projects
None yet
3 participants