Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Dec 12, 2023
1 parent f61e5f2 commit 5418828
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions basedtyping/runtime_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,9 @@ def _eval_type(t, globalns, localns, recursive_guard=frozenset()):
return t


class ForwardRef(_Final, _root=True):
class BasedForwardRef(_Final, _root=True):
"""Internal wrapper to hold a forward reference."""

__slots__ = (
"__forward_arg__",
"__forward_code__",
"__forward_evaluated__",
"__forward_value__",
"__forward_is_argument__",
"__forward_is_class__",
"__forward_module__",
)

def __init__(self, arg, is_argument=True, module=None, *, is_class=False):
if isinstance(arg, str):
# If we do `def f(*args: *Ts)`, then we'll have `arg = '*Ts'`.
Expand All @@ -181,9 +171,6 @@ def __init__(self, arg, is_argument=True, module=None, *, is_class=False):
code = compile(arg_to_compile, "<string>", "eval")
except SyntaxError:
raise SyntaxError(f"Forward reference must be an expression -- got {arg!r}")
except TypeError as t:
print(arg_to_compile.body, t)
...
self.__forward_arg__ = arg
self.__forward_code__ = code
self.__forward_evaluated__ = False
Expand Down Expand Up @@ -226,35 +213,6 @@ def _evaluate(self, globalns, localns, recursive_guard):
self.__forward_evaluated__ = True
return self.__forward_value__

def __eq__(self, other):
if not isinstance(other, ForwardRef):
return NotImplemented
if self.__forward_evaluated__ and other.__forward_evaluated__:
return (
self.__forward_arg__ == other.__forward_arg__
and self.__forward_value__ == other.__forward_value__
)
return (
self.__forward_arg__ == other.__forward_arg__
and self.__forward_module__ == other.__forward_module__
)

def __hash__(self):
return hash((self.__forward_arg__, self.__forward_module__))

def __or__(self, other):
return Union[self, other]

def __ror__(self, other):
return Union[other, self]

def __repr__(self):
if self.__forward_module__ is None:
module_repr = ""
else:
module_repr = f", module={self.__forward_module__!r}"
return f"ForwardRef({self.__forward_arg__!r}{module_repr})"


class BasedTypeParser(NodeTransformer):
in_subscript = 0
Expand Down

0 comments on commit 5418828

Please sign in to comment.