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

undefined-variable is not detected when import is used for more than type hinting #9587

Closed
mikhail-mmlc opened this issue May 2, 2024 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@mikhail-mmlc
Copy link

mikhail-mmlc commented May 2, 2024

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

@mikhail-mmlc mikhail-mmlc added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 2, 2024
@jacobtylerwalls
Copy link
Member

Thanks for the report. Duplicate of #8893

@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants