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

PIE796 false-positives on enum member cast in pyi files #15132

Open
Avasam opened this issue Dec 24, 2024 · 1 comment · May be fixed by #15141
Open

PIE796 false-positives on enum member cast in pyi files #15132

Avasam opened this issue Dec 24, 2024 · 1 comment · May be fixed by #15141
Labels
bug Something isn't working rule Implementing or modifying a lint rule

Comments

@Avasam
Copy link

Avasam commented Dec 24, 2024

Found this whilst applying various Ruff groups on typeshed out of curiosity.

According to the updated typing spec for typing enums (see Mypy: Change to Enum Membership Semantics and https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members, this is the recommended way to type an enum in stubs where the type is known but the value isn't:

class Key(enum.Enum):
    alt = cast(KeyCode, ...)
    alt_l = cast(KeyCode, ...)
    alt_r = cast(KeyCode, ...)
    alt_gr = cast(KeyCode, ...)
    # ...

This will trigger PIE796

However I think that a fix could be simpler than that: This rule probably shouldn't apply to stubs as it's out of the control of a stub's author (ref #14535 )

ruff 0.8.4
command: ruff check --select=PIE --isolated

@dylwil3 dylwil3 added bug Something isn't working rule Implementing or modifying a lint rule labels Dec 24, 2024
@InSyncWithFoo
Copy link
Contributor

Rather than disabling the entire rule, I think the pattern should simply be ignored for stub files when checking for duplicates. It is possible that a stub author might add two members with the same value by mistake (say, via a copy and paste error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants