]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46603: improve coverage of `typing._strip_annotations` (GH-31063)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 19 Feb 2022 02:15:56 +0000 (18:15 -0800)
committerGitHub <noreply@github.com>
Sat, 19 Feb 2022 02:15:56 +0000 (18:15 -0800)
(cherry picked from commit 25c0b9d243b64ccd2eeab483089eaf7e4b4d5834)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_typing.py

index c4c06008d91fa01ce09484f159758a1378902ec3..8ced27824205dfd1fc08827ef1bbfea437819692 100644 (file)
@@ -3305,6 +3305,15 @@ class GetTypeHintTests(BaseTestCase):
             {"x": typing.Annotated[int | float, "const"]}
         )
 
+    def test_get_type_hints_annotated_in_union(self):  # bpo-46603
+        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']]},
+        )
+
     def test_get_type_hints_annotated_refs(self):
 
         Const = Annotated[T, "Const"]