Skip to content

Commit

Permalink
use PythonReturnType for as python return type
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Mar 22, 2024
1 parent 15f4c2e commit f806e68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions clvm/SExp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions clvm/as_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f806e68

Please sign in to comment.