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 1908a4a

Browse filesBrowse files
committed
modify broken test, move test to forwardref format group
1 parent d810953 commit 1908a4a
Copy full SHA for 1908a4a

File tree

Expand file treeCollapse file tree

1 file changed

+26
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-24
lines changed

‎Lib/test/test_annotationlib.py

Copy file name to clipboardExpand all lines: Lib/test/test_annotationlib.py
+26-24Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ def f(
115115
self.assertEqual(z_anno, support.EqualToForwardRef("some(module)", owner=f))
116116

117117
alpha_anno = anno["alpha"]
118-
self.assertIsInstance(alpha_anno, ForwardRef)
119-
self.assertEqual(alpha_anno, support.EqualToForwardRef("some | obj", owner=f))
118+
self.assertIsInstance(alpha_anno, Union)
119+
self.assertEqual(
120+
typing.get_args(alpha_anno),
121+
(support.EqualToForwardRef("some", owner=f), support.EqualToForwardRef("obj", owner=f))
122+
)
120123

121124
beta_anno = anno["beta"]
122125
self.assertIsInstance(beta_anno, ForwardRef)
@@ -126,6 +129,27 @@ def f(
126129
self.assertIsInstance(gamma_anno, ForwardRef)
127130
self.assertEqual(gamma_anno, support.EqualToForwardRef("some < obj", owner=f))
128131

132+
def test_partially_nonexistent_union(self):
133+
# Test unions with '|' syntax equal unions with typing.Union[] with some forwardrefs
134+
class UnionForwardrefs:
135+
pipe: str | undefined
136+
union: Union[str, undefined]
137+
138+
annos = get_annotations(UnionForwardrefs, format=Format.FORWARDREF)
139+
140+
match = (
141+
str,
142+
support.EqualToForwardRef("undefined", is_class=True, owner=UnionForwardrefs)
143+
)
144+
145+
self.assertEqual(
146+
typing.get_args(annos["pipe"]),
147+
typing.get_args(annos["union"])
148+
)
149+
150+
self.assertEqual(typing.get_args(annos["pipe"]), match)
151+
self.assertEqual(typing.get_args(annos["union"]), match)
152+
129153

130154
class TestSourceFormat(unittest.TestCase):
131155
def test_closure(self):
@@ -936,28 +960,6 @@ def __call__(self):
936960
annotationlib.get_annotations(obj, format=format), {}
937961
)
938962

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-
961963
def test_pep695_generic_class_with_future_annotations(self):
962964
ann_module695 = inspect_stringized_annotations_pep695
963965
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.