Skip to content

Commit

Permalink
almost, but not quite
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Dec 15, 2023
1 parent bdbb737 commit e66b640
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion clvm/op_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def operators_for_dict(
return d


def operators_for_module(keyword_to_atom: Dict[str, bytes], mod: types.ModuleType, op_name_lookup: Optional[Dict[str, str]] = None) -> Dict[bytes, OperatorProtocol]:
def operators_for_module(
keyword_to_atom: Dict[str, bytes],
mod: types.ModuleType,
op_name_lookup: Optional[Dict[str, str]] = None,
) -> Dict[bytes, OperatorProtocol]:
if op_name_lookup is None:
op_name_lookup = {}
return operators_for_dict(keyword_to_atom, mod.__dict__, op_name_lookup)
17 changes: 9 additions & 8 deletions clvm/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


if typing.TYPE_CHECKING:
from .SExp import SExp
from .SExp import CastableType, SExp


MAX_SINGLE_BYTE = 0x7F
Expand All @@ -30,12 +30,13 @@

T = typing.TypeVar("T")

ToSExp = typing.Callable[["CastableType"], CLVMStorage]

OpCallable = typing.Callable[
["OpStackType", "ValStackType", typing.BinaryIO, typing.Type], None
["OpStackType", "ValStackType", typing.BinaryIO, ToSExp], None
]

ValStackType = typing.List["SExp"]
ValStackType = typing.List[CLVMStorage]
OpStackType = typing.List[OpCallable]


Expand Down Expand Up @@ -100,7 +101,7 @@ def sexp_to_stream(sexp: SExp, f: typing.BinaryIO) -> None:


def _op_read_sexp(
op_stack: OpStackType, val_stack: ValStackType, f: typing.BinaryIO, to_sexp: typing.Callable[[bytes], SExp],
op_stack: OpStackType, val_stack: ValStackType, f: typing.BinaryIO, to_sexp: ToSExp,
) -> None:
blob = f.read(1)
if len(blob) == 0:
Expand All @@ -118,14 +119,14 @@ def _op_cons(
op_stack: OpStackType,
val_stack: ValStackType,
f: typing.BinaryIO,
to_sexp: typing.Callable[[typing.Tuple[SExp, SExp]], SExp],
to_sexp: ToSExp,
) -> None:
right = val_stack.pop()
left = val_stack.pop()
val_stack.append(to_sexp((left, right)))


def sexp_from_stream(f: typing.BinaryIO, to_sexp: typing.Callable[[SExp], T]) -> T:
def sexp_from_stream(f: typing.BinaryIO, to_sexp: ToSExp) -> CLVMStorage:
op_stack: OpStackType = [_op_read_sexp]
val_stack: ValStackType = []

Expand Down Expand Up @@ -188,8 +189,8 @@ def sexp_buffer_from_stream(f: typing.BinaryIO) -> bytes:


def _atom_from_stream(
f: typing.BinaryIO, b: int, to_sexp: typing.Callable[[bytes], T]
) -> T:
f: typing.BinaryIO, b: int, to_sexp: ToSExp
) -> CLVMStorage:
if b == 0x80:
return to_sexp(b"")
if b <= MAX_SINGLE_BYTE:
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ files = clvm,tests,*.py
show_error_codes = True
warn_unused_ignores = True

;disallow_any_generics = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
Expand Down

0 comments on commit e66b640

Please sign in to comment.