-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Bug description
There is a difference in behavior inside conditional branches depending on if the branch is reachable or not. If it is unreachable, then undefined-variable warnings are emitted, but no-member warnings are not (whereas if it is reachable, both undefined-variable and no-member warnings are emitted).
For example:
#!/usr/bin/env python3
"""False negative no-member"""
import datetime
SOME_BOOL = False
if SOME_BOOL:
print(bar)
print(datetime.does_not_exist)This does not report no-member for datetime.does_not_exist. However, if we change SOME_BOOL = False to SOME_BOOL = True, then the no-member warning is emitted.
This can also happen for more complex conditionals, where it's not clear whether or not the branch is reachable. If pylint is performing fewer checks in conditional branches that it determines are unreachable as a performance optimization, then it probably should at least report that the branch as unreachable.
Thank you!
Configuration
No response
Command used
pylint test.pyPylint output
************* Module test
test.py:7:10: E0602: Undefined variable 'bar' (undefined-variable)
Expected behavior
************* Module test
test.py:7:10: E0602: Undefined variable 'bar' (undefined-variable)
test.py:8:10: E1101: Module 'datetime' has no 'does_not_exist' member (no-member)
Pylint version
pylint 3.0.3
astroid 3.0.1
Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]OS / Environment
RHEL8
Additional dependencies
No response