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: `typing._strip_annotations` is not fully covered
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, JelleZijlstra, gvanrossum, kj, miss-islington, sobolevn
Priority: normal Keywords: patch

Created on 2022-02-01 21:17 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31063 merged sobolevn, 2022-02-01 21:20
PR 31423 merged miss-islington, 2022-02-19 01:54
PR 31424 closed miss-islington, 2022-02-19 01:54
Messages (3)
msg412308 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-02-01 21:17
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!
msg413524 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-19 01:54
New changeset 25c0b9d243b64ccd2eeab483089eaf7e4b4d5834 by Nikita Sobolev in branch 'main':
bpo-46603: improve coverage of `typing._strip_annotations` (GH-31063)
https://github.com/python/cpython/commit/25c0b9d243b64ccd2eeab483089eaf7e4b4d5834
msg413527 - (view) Author: miss-islington (miss-islington) Date: 2022-02-19 02:16
New changeset 103f3ca80616958b4e608e9176b9c12cfc80f68b by Miss Islington (bot) in branch '3.10':
bpo-46603: improve coverage of `typing._strip_annotations` (GH-31063)
https://github.com/python/cpython/commit/103f3ca80616958b4e608e9176b9c12cfc80f68b
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90761
2022-02-19 02:16:08miss-islingtonsetmessages: + msg413527
2022-02-19 01:54:30JelleZijlstrasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-19 01:54:11miss-islingtonsetpull_requests: + pull_request29559
2022-02-19 01:54:08miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29558
2022-02-19 01:54:04JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg413524
2022-02-01 21:20:36sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29248
2022-02-01 21:17:41sobolevncreate