mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)
Noticed by @serhiy-storchaka in the bpo. `typing`'s types were not showing the parameterized generic.
Eg. previously:
```python
>>> typing.Union[dict[str, float], list[int]]
'typing.Union[dict, list]'
```
Now:
```python
>>> typing.Union[dict[str, float], list[int]]
'typing.Union[dict[str, float], list[int]]'
```
Automerge-Triggered-By: GH:gvanrossum
(cherry picked from commit 1f7dfb277e
)
Co-authored-by: kj <28750310+Fidget-Spinner@users.noreply.github.com>
This commit is contained in:
parent
4c239a3222
commit
e81e09bfc8
3 changed files with 12 additions and 0 deletions
|
@ -160,6 +160,8 @@ def _type_repr(obj):
|
|||
typically enough to uniquely identify a type. For everything
|
||||
else, we fall back on repr(obj).
|
||||
"""
|
||||
if isinstance(obj, types.GenericAlias):
|
||||
return repr(obj)
|
||||
if isinstance(obj, type):
|
||||
if obj.__module__ == 'builtins':
|
||||
return obj.__qualname__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue