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

stubtest: Support type_check_only decorator #15146

Open
Avasam opened this issue Apr 26, 2023 · 1 comment
Open

stubtest: Support type_check_only decorator #15146

Avasam opened this issue Apr 26, 2023 · 1 comment

Comments

@Avasam
Copy link
Sponsor Contributor

Avasam commented Apr 26, 2023

Feature

I would like stubtest to support checking the type_check_only decorator.
This means something marked with type_check_only that DOES exist at runtime is an error.
And something that DOES NOT exist at runtime, and is marked with type_check_only should pass.

Pitch

Instead of marking stub-only classes and methods as private in typeshed, they can be marked with @type_check_only, which is designed for that exact purpose. Private may or may not be found at runtime, and users sometimes don't have a choice to use them, and basically have to guess whether they need to wrap the import in TYPE_CHECK_ONLY or not.
This would also promote marking as type_check_only special methods that don't exist at runtime, but are added to support some typechecker features, in typeshed.

Related: #9531

@Avasam
Copy link
Sponsor Contributor Author

Avasam commented Sep 23, 2023

Could I get the topic-stubtest label here?

sobolevn added a commit that referenced this issue Nov 11, 2023
There are several `TODO` items for the future (not in this PR):
- [ ] Add an error code to disallow importing things that are decorated
with `@type_check_only`
- [ ] Support `@overload`ed functions. But, how? There are two options:
we can treat individual overload cases as `@type_check_only` or we can
treat the whole func. Since `typeshed` does not have any examples of
this, I prefer to defer this discussion to somewhere else and support
this when we decide

Refs #15146

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants