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

New rule: prefer x: Final = 42 over x: Final[Literal[42]] #469

Merged
merged 3 commits into from
Mar 17, 2024

Conversation

tomasr8
Copy link
Contributor

@tomasr8 tomasr8 commented Mar 16, 2024

closes #468

Here it goes :)

There is an interaction between this new rule (Y064) and Y061 (which warns for Literal[None]) where it's not entirely clear to me what to do. For example, in this case:

x: Final[Literal[None]]

you'd get both Y064 and Y061. I think in this case turning it into x: Final = None is probably nicer so I decided to not emit Y061 if Y064 would also be emitted.

On the other hand, this seems like a pretty unusual case (no examples in typeshed) so maybe it's not needed?

Copy link

⚠ Flake8 diff showing the effect of this PR on typeshed:

> ./stubs/croniter/croniter/croniter.pyi:39:5: Y064 Use "MONTHS_IN_YEAR: Final = 12" instead of "MONTHS_IN_YEAR: Final[Literal[12]]"
> ./stubs/pika/pika/compat.pyi:16:1: Y064 Use "PY2: Final = False" instead of "PY2: Final[Literal[False]]"
> ./stubs/pika/pika/compat.pyi:17:1: Y064 Use "PY3: Final = True" instead of "PY3: Final[Literal[True]]"
> ./stubs/pika/pika/compat.pyi:48:1: Y064 Use "EINTR_IS_EXPOSED: Final = False" instead of "EINTR_IS_EXPOSED: Final[Literal[False]]"

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 8e3995d into PyCQA:main Mar 17, 2024
20 checks passed
@tomasr8 tomasr8 deleted the y064 branch March 17, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Final literals
2 participants