classification
Title: Add ability to annotate types.Union
Type: enhancement Stage: patch review
Components: Versions: Python 3.11, Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ROpdebee, gvanrossum, kj, serhiy.storchaka, uriyyo
Priority: normal Keywords: patch

Created on 2021-07-17 10:33 by uriyyo, last changed 2021-07-19 17:03 by kj.

Pull Requests
URL Status Linked Edit
PR 27214 open uriyyo, 2021-07-17 10:34
Messages (2)
msg397720 - (view) Author: Yurii Karabas (uriyyo) * Date: 2021-07-17 10:33
It was discussed at https://bugs.python.org/issue44490
msg397816 - (view) Author: Ken Jin (kj) * (Python triager) Date: 2021-07-19 17:03
Nosied over people from issue44490. This issue addresses msg396895:

Thanks to Ruben for the catch. (message copied over):
```
It also lacks the __module__ attribute, causing it to be unusable in PEP 593 typing.Annotated types:

from typing import Annotated
x: Annotated[int | str, 'test']

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 298, in inner
    return cached(*args, **kwds)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 1594, in __class_getitem__
    return _AnnotatedAlias(origin, metadata)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 1520, in __init__
    super().__init__(origin, origin)
  File "/Users/ruben/.pyenv/versions/3.10.0b3/lib/python3.10/typing.py", line 976, in __init__
    self.__module__ = origin.__module__
AttributeError: 'types.Union' object has no attribute '__module__'. Did you mean: '__reduce__'?
```
History
Date User Action Args
2021-07-19 17:03:27kjsetnosy: + gvanrossum, serhiy.storchaka, kj, ROpdebee

messages: + msg397816
versions: + Python 3.10
2021-07-19 16:20:34uriyyosettitle: Add ability to serialise and annotate types.Union -> Add ability to annotate types.Union
2021-07-17 10:38:01uriyyosettitle: Add ability to serialise and annotated types.Union -> Add ability to serialise and annotate types.Union
2021-07-17 10:34:07uriyyosetkeywords: + patch
stage: patch review
pull_requests: + pull_request25754
2021-07-17 10:33:33uriyyocreate