diff options
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 64b348e..36f9ece 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -734,10 +734,19 @@ class ForwardRef(_Final, _root=True): def __init__(self, arg, is_argument=True, module=None, *, is_class=False): if not isinstance(arg, str): raise TypeError(f"Forward reference must be a string -- got {arg!r}") + + # If we do `def f(*args: *Ts)`, then we'll have `arg = '*Ts'`. + # Unfortunately, this isn't a valid expression on its own, so we + # do the unpacking manually. + if arg[0] == '*': + arg_to_compile = f'({arg},)[0]' # E.g. (*Ts,)[0] + else: + arg_to_compile = arg try: - code = compile(arg, '<string>', 'eval') + code = compile(arg_to_compile, '<string>', 'eval') except SyntaxError: raise SyntaxError(f"Forward reference must be an expression -- got {arg!r}") + self.__forward_arg__ = arg self.__forward_code__ = code self.__forward_evaluated__ = False |