diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index cf0fa0b1604c90..9a5b1aa7469faa 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -8492,6 +8492,14 @@ def test_instantiate_generic(self): self.assertEqual(MyCount([4, 4, 5]), {4: 2, 5: 1}) self.assertEqual(MyCount[int]([4, 4, 5]), {4: 2, 5: 1}) + def test_instantiate_immutable(self): + class C: + def __setattr__(self, key, value): + raise Exception("should be ignored") + + A = Annotated[C, "a decoration"] + self.assertIsInstance(A(), C) + def test_cannot_instantiate_forward(self): A = Annotated["int", (5, 6)] with self.assertRaises(TypeError): @@ -8756,16 +8764,6 @@ class B(str): ... self.assertIs(type(field_c2.__metadata__[0]), float) self.assertIs(type(field_c3.__metadata__[0]), bool) - def test_annotated_callable_returning_immutable(self): - class C: - def __setattr__(self, name, value): - raise Exception('should be ignored') - - class A(str): ... - - annotated = Annotated[C, A("A")] - self.assertIsInstance(annotated(), C) - class TypeAliasTests(BaseTestCase): def test_canonical_usage_with_variable_annotation(self):