File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1946,6 +1946,31 @@ class C:
19461946 global_alias = list
19471947 self .assertEqual (evaluated .evaluate (), list [int ])
19481948
1949+ def test_fwdref_evaluate_argument_mutation (self ):
1950+ class C [T ]:
1951+ nonlocal alias
1952+ x : alias [T ]
1953+
1954+ # Mutable arguments
1955+ globals_ = globals ()
1956+ globals_copy = globals_ .copy ()
1957+ locals_ = locals ()
1958+ locals_copy = locals_ .copy ()
1959+
1960+ # Evaluate the ForwardRef, ensuring we use __cell__ and type params
1961+ get_annotations (C , format = Format .FORWARDREF )["x" ].evaluate (
1962+ globals = globals_ ,
1963+ locals = locals_ ,
1964+ type_params = C .__type_params__ ,
1965+ format = Format .FORWARDREF ,
1966+ )
1967+
1968+ # Check if the passed in mutable arguments equal the originals
1969+ self .assertEqual (globals_ , globals_copy )
1970+ self .assertEqual (locals_ , locals_copy )
1971+
1972+ alias = list
1973+
19491974
19501975class TestAnnotationLib (unittest .TestCase ):
19511976 def test__all__ (self ):
You can’t perform that action at this time.
0 commit comments