Message412308
Right now `coverage` says that this line is not covered at all: https://github.com/python/cpython/blob/bebaa95fd0f44babf8b6bcffd8f2908c73ca259e/Lib/typing.py#L1882
Considering how hard all these `types.UnionType` / `typing.Union` stuff is and that the logic with `reduce` and `operator.or_` is also quite complex, I think it is important to cover it.
It actually took me some time to reach this line, but here's the test I came up with:
```
def test_get_type_hints_annotated_in_union(self):
def with_union(x: int | list[Annotated[str, 'meta']]): ...
self.assertEqual(get_type_hints(with_union), {'x': int | list[str]})
self.assertEqual(
get_type_hints(with_union, include_extras=True),
{'x': int | list[Annotated[str, 'meta']]},
)
```
Note that direct `|` with `Annotated` does not work, because it triggers `_AnnotatedType.__or__`, which returns `typing.Union` and not `types.UnionType`.
I will send a PR with it in a minute :)
Any feedback is welcome! |
|
Date |
User |
Action |
Args |
2022-02-01 21:17:41 | sobolevn | set | recipients:
+ sobolevn, gvanrossum, kj, AlexWaygood |
2022-02-01 21:17:41 | sobolevn | set | messageid: <1643750261.29.0.798402203083.issue46603@roundup.psfhosted.org> |
2022-02-01 21:17:41 | sobolevn | link | issue46603 messages |
2022-02-01 21:17:41 | sobolevn | create | |
|