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

TCH false positive with PEP-695 upper bound specification #7966

Closed
bryanforbes opened this issue Oct 15, 2023 · 1 comment · Fixed by #7968
Closed

TCH false positive with PEP-695 upper bound specification #7966

bryanforbes opened this issue Oct 15, 2023 · 1 comment · Fixed by #7968
Assignees
Labels
bug Something isn't working

Comments

@bryanforbes
Copy link

Running the following command with Ruff 0.0.292:

ruff --target-version py312 --select TCH --isolated --no-cache blah.py

Given the following code:

from __future__ import annotations

from collections.abc import Callable
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .foo import Record

type RecordOrThings = Record | int | str
type RecordCallback[R: Record] = Callable[[R], None]


def process_record[R: Record](record: R) -> None:
    ...


class RecordContainer[R: Record]:
    def add_record(self, record: R) -> None:
        ...

TCH004 is reported on line 7, but all uses of Record are only for annotations.

@charliermarsh charliermarsh added the bug Something isn't working label Oct 15, 2023
@charliermarsh
Copy link
Member

Does look like a bug.

@charliermarsh charliermarsh self-assigned this Oct 15, 2023
charliermarsh added a commit that referenced this issue Oct 16, 2023
## Summary

Given `type RecordOrThings = Record | int | str`, the right-hand side
won't be evaluated at runtime. Same goes for `Record` in `type
RecordCallback[R: Record] = Callable[[R], None]`. This PR modifies the
visitation logic to treat them as typing-only.

Closes #7966.
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

Successfully merging a pull request may close this issue.

2 participants