This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Update/fix types.UnionType to types.Union in Built-in Types documentation
Type: Stage: resolved
Components: Documentation Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, kj, vivekvashist
Priority: normal Keywords: patch

Created on 2021-12-18 10:15 by vivekvashist, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30182 closed vivekvashist, 2021-12-18 13:01
Messages (3)
msg408839 - (view) Author: Vivek Vashist (vivekvashist) * Date: 2021-12-18 10:15
There is an error in https://docs.python.org/3/library/stdtypes.html#types-union example.

Looks like there is no types.UnionType

BROKEN:

>>> import types
>>> isinstance(int | str, types.UnionType)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'types' has no attribute 'UnionType'. Did you mean: 'FunctionType'?
>>> [att for att in dir(types) if 'Union' in att]
['Union']
>>>

WORKING:

>>> import types
>>>
>>> isinstance(int | str, types.Union)
True
>>>

I'll raise a PR shortly.
msg408850 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-12-18 13:59
Thanks for the PR Vivek. Can you please tell me the exact 3.10 version you're running? In earlier 3.10 versions (alpha, beta etc.) types.Union existed, but somewhere later (rc1,rc2) it became types.UnionType.

The final 3.10.0 release has types.UnionType, not types.Union. I suspect you might be running an earlier iteration of 3.10.
msg408868 - (view) Author: Vivek Vashist (vivekvashist) * Date: 2021-12-18 20:49
Thanks Ken. 

You are right I'm using 3.10.0b4. I just tested it on 3.10.0 and it works fine.

>>> import types
>>> isinstance(int | str, types.UnionType)
True
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90280
2021-12-18 20:49:25vivekvashistsetstatus: open -> closed
resolution: not a bug
stage: patch review -> resolved
2021-12-18 20:49:04vivekvashistsetstatus: pending -> open

messages: + msg408868
2021-12-18 13:59:29kjsetstatus: open -> pending
nosy: + kj
messages: + msg408850

2021-12-18 13:01:28vivekvashistsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28401
2021-12-18 10:15:32vivekvashistcreate