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

Add @type_check_only to a few fictional classes in builtins.pyi #8531

Merged
merged 1 commit into from
Aug 11, 2022

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Aug 11, 2022

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))

@github-actions
Copy link
Contributor

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

@AlexWaygood AlexWaygood merged commit a92da58 into master Aug 11, 2022
@AlexWaygood AlexWaygood deleted the type_check_only branch August 11, 2022 10:55
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>
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.

2 participants