Skip to content

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.

3 participants