[New-bugs-announce] [issue40396] Support GenericAlias in typing

Serhiy Storchaka report at bugs.python.org
Sun Apr 26 12:02:57 EDT 2020


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

Currently typing functions get_origin(), get_args() and get_type_hints() do not support GenericAlias.

>>> from typing import *
>>> get_origin(List[int])
<class 'list'>
>>> get_origin(list[int])
>>> get_args(List[int])
(<class 'int'>,)
>>> get_args(list[int])
()
>>> def foo(x: List[ForwardRef('X')], y: list[ForwardRef('X')]) -> None: ...                                                                                                                                                                 
...                                                                                                                                                                                                                                          
>>> class X: ...
... 
>>> get_type_hints(foo)
{'x': typing.List[__main__.X], 'y': list[ForwardRef('X')], 'return': <class 'NoneType'>}

The proposed PR fixes this.

----------
components: Library (Lib)
messages: 367308
nosy: gvanrossum, levkivskyi, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Support GenericAlias in typing
type: enhancement
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40396>
_______________________________________


More information about the New-bugs-announce mailing list