@@ -8492,6 +8492,14 @@ def test_instantiate_generic(self):
8492
8492
self .assertEqual (MyCount ([4 , 4 , 5 ]), {4 : 2 , 5 : 1 })
8493
8493
self .assertEqual (MyCount [int ]([4 , 4 , 5 ]), {4 : 2 , 5 : 1 })
8494
8494
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
+
8495
8503
def test_cannot_instantiate_forward (self ):
8496
8504
A = Annotated ["int" , (5 , 6 )]
8497
8505
with self .assertRaises (TypeError ):
@@ -8756,16 +8764,6 @@ class B(str): ...
8756
8764
self .assertIs (type (field_c2 .__metadata__ [0 ]), float )
8757
8765
self .assertIs (type (field_c3 .__metadata__ [0 ]), bool )
8758
8766
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
-
8769
8767
8770
8768
class TypeAliasTests (BaseTestCase ):
8771
8769
def test_canonical_usage_with_variable_annotation (self ):
0 commit comments