[New-bugs-announce] [issue46529] Improve test coverage of `Union` and `Optional` repr()

Nikita Sobolev report at bugs.python.org
Wed Jan 26 03:39:08 EST 2022


New submission from Nikita Sobolev <mail at sobolevn.me>:

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.

----------
components: Tests
messages: 411715
nosy: gvanrossum, kj, sobolevn
priority: normal
severity: normal
status: open
title: Improve test coverage of `Union` and `Optional` repr()
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46529>
_______________________________________


More information about the New-bugs-announce mailing list