Open
Description
Bug description
With the minimal code below a `W0612` warning is produced for the second except, but it goes if a different variable name is used instead of `exc`. For some reason, using the same variable name in both except blocks confuses the linter and causes the false positive.
try:
pass
except TypeError as exc:
print(exc)
except ValueError as exc:
print(exc)
Configuration
[MASTER]
jobs=0
unsafe-load-any-extension=yes
[MESSAGES CONTROL]
enable=all
disable=I,too-many-lines
[REPORTS]
#reports=yes
msg-template='{path}:{line}:{column}: {msg_id} ({symbol}) {msg}'
[BASIC]
good-names=i,j,c,_
include-naming-hint=yes
[FORMAT]
max-line-length=120
[VARIABLES]
allow-global-unused-variables=no
Command used
I'm using Visual Studio Code Pylance, so the command is like:
`python.exe -m pylint --reports=n --output-format=json --clear-cache-post-run=y --from-stdin minimal.py`
Pylint output
{
"type": "warning",
"module": "erase",
"obj": "",
"line": 5,
"column": 0,
"endLine": 6,
"endColumn": 14,
"path": "C:\\Users\\rauln\\Desktop\\sysbin\\erase.py",
"symbol": "unused-variable",
"message": "Unused variable 'exc'",
"message-id": "W0612"
}
Expected behavior
No W0612
warning issued for that code.
Pylint version
pylint 3.3.4
astroid 3.3.8
Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb 4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)]
OS / Environment
Windows 11 Home 24H2
Visual Studio Code 1.101.0
Pylance 2025.6.1