Closed
Description
You can subclass Annotated[int, "meta"]
:
>>> import typing
>>> class Some(typing.Annotated[int, 'meta']): ...
...
>>> Some.__mro__
(<class '__main__.Some'>, <class 'int'>, <class 'object'>)
But, here are a couple of problems:
- All metadata is lost: so, no reason to use
Annotated
in the first place - https://peps.python.org/pep-0593/ never mentions this use-case
- We assume that
Annotated
cannot be subclassed: https://github.com/python/cpython/blame/53a54b781d1f05f2d0b40ce88b3da92d5d23e9d2/Lib/test/test_typing.py#L6562-L6565 here
I think that Annotated
should not be subclasses and this is a bug.
The PR is incoming :)
I found this while working on #96769