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.

Author sobolevn
Recipients AlexWaygood, gvanrossum, kj, sobolevn
Date 2022-02-01.21:17:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643750261.29.0.798402203083.issue46603@roundup.psfhosted.org>
In-reply-to
Content
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!
History
Date User Action Args
2022-02-01 21:17:41sobolevnsetrecipients: + sobolevn, gvanrossum, kj, AlexWaygood
2022-02-01 21:17:41sobolevnsetmessageid: <1643750261.29.0.798402203083.issue46603@roundup.psfhosted.org>
2022-02-01 21:17:41sobolevnlinkissue46603 messages
2022-02-01 21:17:41sobolevncreate