classification
Title: Support GenericAlias in typing
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, levkivskyi, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-04-26 16:02 by serhiy.storchaka, last changed 2020-04-26 19:27 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19718 merged serhiy.storchaka, 2020-04-26 16:08
Messages (2)
msg367308 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-26 16:02
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.
msg367326 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-26 18:21
New changeset 68b352a6982f51e19bf9b9f4ae61b34f5864d131 by Serhiy Storchaka in branch 'master':
bpo-40396: Support GenericAlias in the typing functions. (GH-19718)
https://github.com/python/cpython/commit/68b352a6982f51e19bf9b9f4ae61b34f5864d131
History
Date User Action Args
2020-04-26 19:27:57serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-26 18:21:15serhiy.storchakasetmessages: + msg367326
2020-04-26 16:08:41serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request19039
2020-04-26 16:02:57serhiy.storchakacreate