[stubtest] Check runtime availability of private types not marked @type_check_only#19574
Open
brianschubert wants to merge 7 commits intopython:masterfrom
Open
[stubtest] Check runtime availability of private types not marked @type_check_only#19574brianschubert wants to merge 7 commits intopython:masterfrom
@type_check_only#19574brianschubert wants to merge 7 commits intopython:masterfrom
Conversation
Collaborator
Author
|
python/typeshed#14512 addresses the new stdlib hits in typeshed thirdy-party stub hits can be seen at https://github.com/brianschubert/typeshed/actions/runs/16697076815/ |
Collaborator
Author
|
These are the third-party stub hits if anyone is interested in investigating some (I'll be sifting through them as I have time) Details |
Collaborator
Author
|
Marking this as ready for review.
|
Contributor
|
Thanks for taking a shot at this ! It's something I've been wanting for a while as well. This works towards #15146 |
This was referenced Mar 15, 2026
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.
Currently, stubtest ignores symbols that are 1) private and 2) not present at runtime. Private names are often used for stub-only constructs (which we don't want stubtest to complain about), but they can also denote actual private runtime types. Without other context, it's often ambiguous which category a private names falls into. For class definitions, we can make the intent explicit by decorating the class with
@type_check_only. Typeshed already does this for the most part, but there's still quite a few cases of stub-only private types that aren't marked@type_check_only(especially in older stubs).Going forward, I think it could a good idea to make stubtest start checking for
@type_check_onlyon private types that are not available at runtime.A few special cases are needed to avoid false positives on types that cannot be marked with
@type_check_only, namely:This PR creates quite a few new errors on typeshed (~100 in stdlib, ~300 in third-party stubs), which we'll probably want to sift through before merging this. So far I've gone through the stdlib hits, all of which seem to be true positives that we'd want to update.