Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fba5efa

Browse filesBrowse files
committed
Add a test for union forward references
1 parent 05d0559 commit fba5efa
Copy full SHA for fba5efa

File tree

Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed

‎Lib/test/test_annotationlib.py

Copy file name to clipboardExpand all lines: Lib/test/test_annotationlib.py
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,28 @@ def __call__(self):
936936
annotationlib.get_annotations(obj, format=format), {}
937937
)
938938

939+
def test_union_forwardref(self):
940+
# Test unions with '|' syntax equal unions with typing.Union[] with forwardrefs
941+
class UnionForwardrefs:
942+
pipe: str | undefined
943+
union: Union[str, undefined]
944+
945+
annos = get_annotations(UnionForwardrefs, format=Format.FORWARDREF)
946+
947+
match = (
948+
str,
949+
support.EqualToForwardRef("undefined", is_class=True, owner=UnionForwardrefs)
950+
)
951+
952+
self.assertEqual(
953+
typing.get_args(annos["pipe"]),
954+
typing.get_args(annos["union"])
955+
)
956+
957+
self.assertEqual(typing.get_args(annos["pipe"]), match)
958+
self.assertEqual(typing.get_args(annos["union"]), match)
959+
960+
939961
def test_pep695_generic_class_with_future_annotations(self):
940962
ann_module695 = inspect_stringized_annotations_pep695
941963
A_annotations = annotationlib.get_annotations(ann_module695.A, eval_str=True)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.