From f806e686a531b98e695b00b6177d34d589fcbb2d Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Fri, 22 Mar 2024 09:54:17 -0400 Subject: [PATCH] use `PythonReturnType` for as python return type --- clvm/SExp.py | 6 +++--- clvm/as_python.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clvm/SExp.py b/clvm/SExp.py index 0f22a99f..deca3366 100644 --- a/clvm/SExp.py +++ b/clvm/SExp.py @@ -5,7 +5,7 @@ import typing_extensions -from .as_python import as_python +from .as_python import PythonReturnType, as_python from .CLVMObject import CLVMObject, CLVMStorage from .EvalError import EvalError @@ -196,7 +196,7 @@ def to(cls: typing.Type[_T_SExp], v: typing.Any) -> _T_SExp: # this will lazily convert elements return cls(to_sexp_type(v)) - def cons(self: _T_SExp, right: _T_SExp) -> _T_SExp: + def cons(self: _T_SExp, right: CastableType) -> _T_SExp: return self.to((self, right)) def first(self: _T_SExp) -> _T_SExp: @@ -249,7 +249,7 @@ def list_len(self) -> int: v = v.rest() return size - def as_python(self) -> typing.Any: + def as_python(self) -> PythonReturnType: return as_python(self) def __str__(self) -> str: diff --git a/clvm/as_python.py b/clvm/as_python.py index 41ecf9a9..c7f9ee98 100644 --- a/clvm/as_python.py +++ b/clvm/as_python.py @@ -53,10 +53,12 @@ def _as_python(op_stack: OpStackType, val_stack: ValStackType) -> None: val_stack.append(t.atom) # type:ignore[arg-type] -def as_python(sexp: SExp) -> Any: +def as_python(sexp: SExp) -> PythonReturnType: op_stack: OpStackType = [_as_python] val_stack: ValStackType = [sexp] while op_stack: op_f = op_stack.pop() op_f(op_stack, val_stack) - return val_stack[-1] + result = val_stack[-1] + assert not isinstance(result, SExp) + return result