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 negative used-before-assignment when the variable is used again in try/except #9941

Open
octaviancorlade opened this issue Sep 20, 2024 · 0 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@octaviancorlade
Copy link

octaviancorlade commented Sep 20, 2024

Bug description

This is highlighted as expected

import requests

try:
    response = requests.get("https://google.com", timeout=1)
except Exception:
    print(response) # correctly raises used-before-assignment

This is not

import requests

try:
    response = requests.get("https://google.com", timeout=1) 
    response2 = response
except Exception:
    print(response) # should still raise used-before-assignment

Command used

pylint script1.py

Pylint output

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

Expected behavior

************* Module script1
script1.py:8:10: E0601: Using variable 'response' before assignment (used-before-assignment)

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

Pylint version

pylint 3.3.0
astroid 3.3.3
Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

Additional dependencies

requests==2.32.3
pylint==3.3.0
@octaviancorlade octaviancorlade added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

1 participant