This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients gvanrossum, kj, serhiy.storchaka
Date 2021-08-21.07:41:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629531662.05.0.587324912826.issue44969@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-08-21 07:41:02serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, kj
2021-08-21 07:41:02serhiy.storchakasetmessageid: <1629531662.05.0.587324912826.issue44969@roundup.psfhosted.org>
2021-08-21 07:41:02serhiy.storchakalinkissue44969 messages
2021-08-21 07:41:01serhiy.storchakacreate