88import itertools
99import pickle
1010from string .templatelib import Template , Interpolation
11+ import random
1112import typing
1213import sys
1314import unittest
@@ -1648,7 +1649,6 @@ def format(format, second, /, *, third, __Format=Format,
16481649 self .assertEqual (annotations , {"x" : Format .VALUE * 5 * 6 })
16491650
16501651 def test_callable_cache_annotate_forwardref_value_fallback (self ):
1651- import random
16521652 # If Format.STRING and Format.VALUE_WITH_FAKE_GLOBALS are not
16531653 # supported fall back to Format.VALUE and convert to strings
16541654 @functools .cache
@@ -1672,6 +1672,28 @@ def format(format, /, __Format=Format,
16721672 new_anns = annotationlib .call_annotate_function (format , Format .FORWARDREF )
16731673 self .assertEqual (annotations , new_anns )
16741674
1675+ def test_callable_wrapped_annotate_forwardref_value_fallback (self ):
1676+ # If Format.STRING and Format.VALUE_WITH_FAKE_GLOBALS are not
1677+ # supported fall back to Format.VALUE and convert to strings
1678+ def multiple_format (fn ):
1679+ inputs = {"x" : int }
1680+ @functools .wraps (fn )
1681+ def format (format , / , __Format = Format ,
1682+ __NotImplementedError = NotImplementedError ):
1683+ if format == __Format .VALUE :
1684+ return {** inputs , ** fn ()}
1685+ else :
1686+ raise __NotImplementedError (format )
1687+
1688+ return format
1689+
1690+ annotations = annotationlib .call_annotate_function (
1691+ multiple_format (lambda : {"y" : str }),
1692+ Format .FORWARDREF ,
1693+ )
1694+
1695+ self .assertEqual (annotations , {"x" : int , "y" : str })
1696+
16751697 def test_callable_object_annotate_string_fakeglobals (self ):
16761698 # If Format.STRING is not supported but Format.VALUE_WITH_FAKE_GLOBALS is
16771699 # prefer that over Format.VALUE
0 commit comments