Skip to content

Make signal global enum constants annotated as literals #13336

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

Merged
merged 2 commits into from
Dec 30, 2024

Conversation

bswck
Copy link

@bswck bswck commented Dec 29, 2024

Apart from regular rewrites of annotations from GLOBAL: EnumClassName to GLOBAL: Literal[EnumClassName.MEMBER], you may notice a small different kind of change:

-    SIG_BLOCK = Sigmasks.SIG_BLOCK
-    SIG_UNBLOCK = Sigmasks.SIG_UNBLOCK
-    SIG_SETMASK = Sigmasks.SIG_SETMASK
+    SIG_BLOCK: Literal[Sigmasks.SIG_BLOCK]
+    SIG_UNBLOCK: Literal[Sigmasks.SIG_UNBLOCK]
+    SIG_SETMASK: Literal[Sigmasks.SIG_SETMASK]

The reason why I did is because this unifies the outcomes across pyright and mypy (reveal_type(SIG_BLOCK) for old SIG_BLOCK is Sigmasks according to mypy and Literal[Sigmasks.SIG_BLOCK] according to pyright) -- with the new version, both checkers see literal types.

This comment has been minimized.

@bswck
Copy link
Author

bswck commented Dec 29, 2024

Interesting failures. I can see the concern mainly being that globals prefer non-alias enum members, but the literal integer values at runtime are effectively correct.

@bswck bswck force-pushed the signal-globals-literal branch from 0a3cefd to ee18e0f Compare December 29, 2024 06:01
@bswck
Copy link
Author

bswck commented Dec 29, 2024

Added # alias comments for clarity and intention assurance.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 7febf03 into python:main Dec 30, 2024
64 checks passed
hoel-bagard pushed a commit to hoel-bagard/typeshed that referenced this pull request Jan 5, 2025
@sobolevn
Copy link
Member

sobolevn commented Feb 7, 2025

We suspect that this is the cause of python/mypy#18628

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.

3 participants