Skip to content

Commit 7289af4

Browse files
committed
fixup! pythongh-115165: Fix Annotated for immutable types
Renamed test_annotated_callable_returning_immutable to test_instantiate_immutable and moved it near the other instantiation tests.
1 parent ff5e885 commit 7289af4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Lib/test/test_typing.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -8492,6 +8492,14 @@ def test_instantiate_generic(self):
84928492
self.assertEqual(MyCount([4, 4, 5]), {4: 2, 5: 1})
84938493
self.assertEqual(MyCount[int]([4, 4, 5]), {4: 2, 5: 1})
84948494

8495+
def test_instantiate_immutable(self):
8496+
class C:
8497+
def __setattr__(self, key, value):
8498+
raise Exception("should be ignored")
8499+
8500+
A = Annotated[C, "a decoration"]
8501+
self.assertIsInstance(A(), C)
8502+
84958503
def test_cannot_instantiate_forward(self):
84968504
A = Annotated["int", (5, 6)]
84978505
with self.assertRaises(TypeError):
@@ -8756,16 +8764,6 @@ class B(str): ...
87568764
self.assertIs(type(field_c2.__metadata__[0]), float)
87578765
self.assertIs(type(field_c3.__metadata__[0]), bool)
87588766

8759-
def test_annotated_callable_returning_immutable(self):
8760-
class C:
8761-
def __setattr__(self, name, value):
8762-
raise Exception('should be ignored')
8763-
8764-
class A(str): ...
8765-
8766-
annotated = Annotated[C, A("A")]
8767-
self.assertIsInstance(annotated(), C)
8768-
87698767

87708768
class TypeAliasTests(BaseTestCase):
87718769
def test_canonical_usage_with_variable_annotation(self):

0 commit comments

Comments
 (0)