New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

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

----------
components: Library (Lib)
messages: 400021
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Subclassing of annotated types does not always work
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44969>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to