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: Improve test coverage of `Union` and `Optional` repr()
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, kj, miss-islington, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-26 08:39 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30911 merged sobolevn, 2022-01-26 08:40
PR 30919 merged miss-islington, 2022-01-26 10:13
PR 30920 merged miss-islington, 2022-01-26 10:13
Messages (4)
msg411715 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-26 08:39
There are several important cases that are missing from current `repr()` tests of `typing.Union` and `typing.Optional`:
1. This condition is not covered at all: `if args[0] is type(None):` https://github.com/python/cpython/blob/7cf285d82ec722d4225297366013e924805171f2/Lib/typing.py#L1236
3. `repr()` of `Union[str, None]` is not directly tested as well
3. `repr()` of `Union` with more that 2 parameters with `None` is not covered. This is an important corner case because of this condition: `if len(args) == 2:` https://github.com/python/cpython/blob/7cf285d82ec722d4225297366013e924805171f2/Lib/typing.py#L1235

I will send a PR with new assertions.
msg411729 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2022-01-26 10:13
New changeset d0c690b5f85c679de6059cf353fe0524e905530e by Nikita Sobolev in branch 'main':
bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)
https://github.com/python/cpython/commit/d0c690b5f85c679de6059cf353fe0524e905530e
msg411731 - (view) Author: miss-islington (miss-islington) Date: 2022-01-26 10:39
New changeset c730342005edf67333c37b575b419e2fc67d232b by Miss Islington (bot) in branch '3.10':
bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)
https://github.com/python/cpython/commit/c730342005edf67333c37b575b419e2fc67d232b
msg411733 - (view) Author: miss-islington (miss-islington) Date: 2022-01-26 10:40
New changeset 29eefcc9c688bc4097f2660de1fa846c5ea54735 by Miss Islington (bot) in branch '3.9':
bpo-46529: increase coverage of `typing.Union.__repr__` method (GH-30911)
https://github.com/python/cpython/commit/29eefcc9c688bc4097f2660de1fa846c5ea54735
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90687
2022-01-26 14:36:00kjsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-26 10:40:47miss-islingtonsetmessages: + msg411733
2022-01-26 10:39:51miss-islingtonsetmessages: + msg411731
2022-01-26 10:13:20miss-islingtonsetpull_requests: + pull_request29099
2022-01-26 10:13:16miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29098
2022-01-26 10:13:16kjsetmessages: + msg411729
2022-01-26 08:40:06sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29090
2022-01-26 08:39:08sobolevncreate