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: Convert None to NoneType in the union type constructor
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, kj, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-07-14 10:51 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27136 merged serhiy.storchaka, 2021-07-14 10:55
PR 27141 closed kj, 2021-07-14 17:01
PR 27142 merged serhiy.storchaka, 2021-07-14 17:01
Messages (3)
msg397475 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-14 10:51
There is a difference between typing.Union and the builtin union type in representing None in __args__:

>>> import typing
>>> typing.Union[int, None].__args__
(<class 'int'>, <class 'NoneType'>)
>>> typing.Union[int, type(None)].__args__
(<class 'int'>, <class 'NoneType'>)
>>> (int | None).__args__
(<class 'int'>, None)
>>> (int | type(None)).__args__
(<class 'int'>, <class 'NoneType'>)

The former converts None to NoneType, the latter leaves it as is, and only performs conversion in __instancecheck__ and __subclasscheck__. In the discussion for issue44606 it was proposed to convert None to NoneType in the union type constructor to make more uniform with typing.Union and simplify __instancecheck__ and __subclasscheck__.
msg397496 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-14 16:54
New changeset b81cac05606c84958b52ada09f690463a3c7e949 by Serhiy Storchaka in branch 'main':
bpo-44635: Convert None to NoneType in the union type constructor (GH-27136)
https://github.com/python/cpython/commit/b81cac05606c84958b52ada09f690463a3c7e949
msg397525 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-15 07:15
New changeset 6dec5255829a31826990ea40ca106cc496570df2 by Serhiy Storchaka in branch '3.10':
[3.10] bpo-44635: Convert None to NoneType in the union type constructor (GH-27136). (GH-27142)
https://github.com/python/cpython/commit/6dec5255829a31826990ea40ca106cc496570df2
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88801
2021-07-15 07:15:55serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-15 07:15:28serhiy.storchakasetmessages: + msg397525
2021-07-14 17:01:33serhiy.storchakasetpull_requests: + pull_request25684
2021-07-14 17:01:01kjsetpull_requests: + pull_request25683
2021-07-14 16:54:58serhiy.storchakasetmessages: + msg397496
2021-07-14 10:55:13serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request25679
2021-07-14 10:54:46serhiy.storchakasetnosy: + gvanrossum, kj
2021-07-14 10:51:57serhiy.storchakacreate