Skip to content

Commit

Permalink
fixup! pythongh-115165: Fix Annotated for immutable types
Browse files Browse the repository at this point in the history
Renamed test_annotated_callable_returning_immutable to
test_instantiate_immutable and moved it near the other instantiation
tests.
  • Loading branch information
dave-shawley committed Feb 9, 2024
1 parent ff5e885 commit 7289af4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 7289af4

Please sign in to comment.