It works only with simple types
>>> class X(Annotated[list, 'annotation']): pass
...
But not with type aliases
>>> class X(Annotated[List[int], 'annotation']): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: _GenericAlias.__init__() takes 3 positional arguments but 4 were given
>>> class X(Annotated[list[int], 'annotation']): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: GenericAlias expected 2 arguments, got 3
And even if the original type is not subclassable, the error message is not always clear:
>>> class X(Annotated[Union[int, str], 'annotation']): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: _GenericAlias.__init__() takes 3 positional arguments but 4 were given
>>> class X(Annotated[int | str, 'annotation']): pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: _GenericAlias.__init__() takes 3 positional arguments but 4 were given
|