Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Sep 15, 2024
1 parent 1d9b923 commit e5cf3ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/basedtyping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import ast
import sys
import typing
import warnings
Expand Down Expand Up @@ -620,10 +621,12 @@ def __init__(self, arg: str, *, is_argument=True, module: object = None, is_clas
warnings.simplefilter("ignore", category=SyntaxWarning)
code = compile(arg_to_compile, "<string>", "eval")
except SyntaxError:
# Callable: () -> int
if "->" not in arg_to_compile:
try:
ast.parse(arg_to_compile, mode="func_type")
except SyntaxError:
raise SyntaxError(f"invalid syntax in ForwardRef: {arg_to_compile}?") from None
code = compile("'un-representable callable type'", "<string>", "eval")
else:
code = compile("'un-representable callable type'", "<string>", "eval")

self.__forward_arg__ = arg
self.__forward_code__ = code
Expand Down

0 comments on commit e5cf3ca

Please sign in to comment.