Add @type_check_only to a few fictional classes in builtins.pyi#8531
Merged
AlexWaygood merged 1 commit intomasterfrom Aug 11, 2022
Merged
Add @type_check_only to a few fictional classes in builtins.pyi#8531AlexWaygood merged 1 commit intomasterfrom
@type_check_only to a few fictional classes in builtins.pyi#8531AlexWaygood merged 1 commit intomasterfrom
Conversation
srittau
approved these changes
Aug 11, 2022
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
tsibley
added a commit
to nextstrain/cli
that referenced
this pull request
Aug 30, 2023
pyright 1.1.325 (released yesterday) added support for @type_check_only
decorators¹, which were added (a year ago) to the builtins.ellipsis type
of the stdlib typeshed². This type is available only during
type-checking and doesn't actually exist at runtime, but previously
pyright didn't care about that (and mypy still doesn't). Now it does,
noticed thanks to scheduled CI, and throws an error like:
"ellipsis" is marked as @type_check_only and can be used only in
type annotations (reportGeneralTypeIssues)
Explicitly clarify to pyright that our variable is a type alias³ and not
a value also used at runtime so it knows its ok to use the type of
Ellipsis (via a forward reference to the now-you-see-it, now-you-don't
builtins.ellipsis).
Relatedly, we can switch from 'builtins.ellipsis' → types.EllipsisType
on Python ≥3.10⁴ and stop using the private/internal type for Ellipsis.
I'll do that in the subsequent commit.
¹ <microsoft/pyright#5817>
² <python/typeshed@a92da58>
<python/typeshed#8531>
³ <https://docs.python.org/3/library/typing.html#typing.TypeAlias>
<https://peps.python.org/pep-0613/>
⁴ <https://docs.python.org/3/library/types.html#types.EllipsisType>
<python/cpython#85976>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not all type checkers support this decorator (mypy notably doesn't), but adding the decorator doesn't interfere with them at all, it's nice to explicitly mark these as works of fiction, and it could plausibly help out IDEs/autocompletion tools such as PyCharm/Jedi that have to patch typeshed to remove these symbols (#2999 (comment))