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

conditional import X.Y causes false positive possibly-used-before-assignment #10081

Closed
jwilk opened this issue Nov 13, 2024 · 0 comments · Fixed by #10240
Closed

conditional import X.Y causes false positive possibly-used-before-assignment #10081

jwilk opened this issue Nov 13, 2024 · 0 comments · Fixed by #10240
Labels
Backported C: used-before-assignment Issues related to 'used-before-assignment' check False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@jwilk
Copy link
Contributor

jwilk commented Nov 13, 2024

Bug description

if input():
    import os.path
else:
    os = None
if os:
    pass

Command used

$ pylint -E condimport.py 

Pylint output

condimport.py:5:3: E0606: Possibly using variable 'os' before assignment (possibly-used-before-assignment)

Expected behavior

The os variable is set in both branches, so no error should be reported.

Pylint version

pylint 3.3.1
astroid 3.3.5
Python 3.13.0 (main, Oct  8 2024, 08:51:27) [GCC 9.4.0]
jwilk added a commit to jwilk/distutils644 that referenced this issue Nov 13, 2024
Fixes:

    distutils644.py:123: E: possibly-used-before-assignment [] Possibly using variable 'wheel' before assignment

pylint-dev/pylint#10081
@Pierre-Sassoulas Pierre-Sassoulas added 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 labels Nov 13, 2024
@jacobtylerwalls jacobtylerwalls added the C: used-before-assignment Issues related to 'used-before-assignment' check label Nov 17, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.3.5 milestone Feb 20, 2025
@jacobtylerwalls jacobtylerwalls added Backported and removed Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported C: used-before-assignment Issues related to 'used-before-assignment' check 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