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-positive TCH003: lint.typing-modules setting is not honored in the typing module itself #11733

Open
bersbersbers opened this issue Jun 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@bersbersbers
Copy link
Contributor

lint.typing-modules allows defining compatibility modules whose exports will be treated the same as the exports from the typing module. However, this does not seem to work in the module itself - ruff does not seem to understand that TYPE_CHECKING defines a type-checking block in this example:

bug.py

from __future__ import annotations

import typing

def is_type_checking() -> bool:
    # This will be more complicated, obviously
    return 4 < 10

# This should be considered a typing module's TYPE_CHECKING variable:
TYPE_CHECKING = typing.TYPE_CHECKING or is_type_checking()

if TYPE_CHECKING:
    # So I consider this a false-negative TCH003
    from collections.abc import Iterable

def fun(_var: Iterable[str]) -> None:
    return None

pyproject.toml

[tool.ruff]
lint.select = ["TCH003"]
lint.typing-modules = ["bug"]

ruff check bug.py

bug.py:14:33: TCH003 Move standard library import `collections.abc.Iterable` into a type-checking block
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

ruff --version

ruff 0.4.7
@charliermarsh charliermarsh added the bug Something isn't working label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants