`undefined-variable` is not detected when import is used for more than type hinting
mikhail-mmlc opened this issue · 1 comments
mikhail-mmlc commented
Bug description
Pylint doesn't detect cases where objects imported from the typing.TYPE_CHECKING
block are used outside of type annotations.
"""Example."""
from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from pathlib import Path
def example_function(path: Path) -> bool:
"""Path is not imported in production code."""
return path < Path("example.txt") # undefined-variable should be detected here but it's not
Configuration
No response
Command used
`pylint --enable=all example.py`
Pylint output
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Expected behavior
************* Module example
example.py:12:18: E0602: Undefined variable 'Path' (undefined-variable)
Pylint version
pylint 3.1.0
astroid 3.1.0
Python 3.10.14 (main, Apr 24 2024, 07:55:43) [GCC 10.2.1 20210110]
pylint 2.17.7
astroid 2.15.8
Python 3.10.14 (main, Apr 24 2024, 07:55:43) [GCC 10.2.1 20210110]
OS / Environment
Debian GNU/Linux 11 (bullseye)
Additional dependencies
No response
jacobtylerwalls commented
Thanks for the report. Duplicate of #8893