Skip to content

Conversation

@jorenham
Copy link
Contributor

@jorenham jorenham commented Dec 2, 2025

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 on lines +1869 to +1870
msg = f"all base classes of {instance.type.fullname!r} are @type_check_only"
assert False, msg
Copy link
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 on lines +1874 to +1875
def visit_type_alias_type(self, t: mypy.types.TypeAliasType, /) -> mypy.types.Type:
return t
Copy link
Contributor Author

@jorenham jorenham Dec 2, 2025

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

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

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

2 participants