Skip to content

[stubtest] transparent @type_check_only types - #20352

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
jorenham:gh-20223
Dec 2, 2025
Merged

[stubtest] transparent @type_check_only types#20352
ilevkivskyi merged 1 commit into
python:masterfrom
jorenham:gh-20223

Conversation

@jorenham

@jorenham jorenham commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

This closes #20223 by mapping a @type_check_only type (of an instance) to its first non-@type_check_only superclass.

A use case is for annotating specific numpy.ufunc instances through @type_check_only specialized ufunc subtypes, as explained in #20223.

Comment thread mypy/stubtest.py
Comment on lines +1869 to +1870
msg = f"all base classes of {instance.type.fullname!r} are @type_check_only"
assert False, msg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume here that it will eventually always have encountered builtins.object before getting here.

Comment thread mypy/stubtest.py
Comment on lines +1874 to +1875
def visit_type_alias_type(self, t: mypy.types.TypeAliasType, /) -> mypy.types.Type:
return t

@jorenham jorenham Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method might look a bit awkward, but we need it because it's marked as abstract in mypy.types.TypeTranslator (i.e., without it there'd be a squiggly).

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, thanks!

@ilevkivskyi
ilevkivskyi merged commit f0d6113 into python:master Dec 2, 2025
15 checks passed
@jorenham
jorenham deleted the gh-20223 branch December 2, 2025 16:18
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.

stubtest false positive: @type_check_only subtypes of numpy.ufunc

3 participants