Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSZ utils to mypy checking scope #1707

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ SOLIDITY_FILE_NAME = deposit_contract.json
DEPOSIT_CONTRACT_TESTER_DIR = ${SOLIDITY_DEPOSIT_CONTRACT_DIR}/web3_tester
CONFIGS_DIR = ./configs

CURRENT_DIR = ${CURDIR}
MYPY_STUBS_DIR = $(CURRENT_DIR)/mypy_stubs

# Collect a list of generator names
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/.)))
# Map this list of generator paths to "gen_{generator name}" entries
Expand Down Expand Up @@ -44,6 +47,8 @@ export DAPP_SRC:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)
export DAPP_LIB:=$(SOLIDITY_DEPOSIT_CONTRACT_DIR)/lib
export DAPP_JSON:=build/combined.json

MYPY_CONFIG_NAME = mypy.ini

.PHONY: clean partial_clean all test citest lint generate_tests pyspec install_test open_cov \
install_deposit_contract_tester test_deposit_contract install_deposit_contract_compiler \
compile_deposit_contract test_compile_deposit_contract check_toc \
Expand Down Expand Up @@ -136,6 +141,7 @@ codespell:
lint: pyspec
. venv/bin/activate; cd $(PY_SPEC_DIR); \
flake8 --config $(LINTER_CONFIG_FILE) ./eth2spec \
&& export MYPYPATH=$(MYPY_STUBS_DIR) \
&& pylint --disable=all --enable unused-argument ./eth2spec/phase0 ./eth2spec/altair ./eth2spec/bellatrix \
&& mypy --config-file $(LINTER_CONFIG_FILE) -p eth2spec.phase0 -p eth2spec.altair -p eth2spec.bellatrix -p eth2spec.capella

Expand Down
11 changes: 11 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[mypy]

disallow_incomplete_defs = True
disallow_untyped_defs = True
disallow_subclassing_any = True

warn_unused_ignores = True
warn_unused_configs = True
warn_redundant_casts = True

ignore_missing_imports = True
Empty file added mypy_stubs/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions mypy_stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Stubs for remerkleable (Python 3)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

Empty file.
11 changes: 11 additions & 0 deletions mypy_stubs/eth2spec/utils/ssz/ssz_impl.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from remerkleable.basic import uint as uint
from remerkleable.byte_arrays import Bytes32
from remerkleable.core import View
from typing import TypeVar

def serialize(obj: View) -> bytes: ...
def hash_tree_root(obj: View) -> Bytes32: ...
def uint_to_bytes(n: uint) -> bytes: ...
V = TypeVar('V', bound=View)

def copy(obj: V) -> V: ...
8 changes: 8 additions & 0 deletions mypy_stubs/eth2spec/utils/ssz/ssz_typing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from remerkleable.basic import bit as bit, boolean as boolean, byte as byte, uint as uint, uint128 as uint128, uint16 as uint16, uint256 as uint256, uint32 as uint32, uint64 as uint64, uint8 as uint8
from remerkleable.bitfields import Bitlist as Bitlist, Bitvector as Bitvector
from remerkleable.byte_arrays import ByteList as ByteList, Bytes1 as Bytes1, Bytes32 as Bytes32, Bytes4 as Bytes4, Bytes48 as Bytes48, Bytes8 as Bytes8, Bytes96 as Bytes96
from remerkleable.complex import Container as Container, List as List, Vector as Vector
from remerkleable.core import BasicView as BasicView, Path as Path, View as View
from typing import Any

Bytes20: Any
Empty file.
100 changes: 100 additions & 0 deletions mypy_stubs/remerkleable/basic.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from remerkleable.core import BasicView as BasicView, ObjParseException as ObjParseException, ObjType as ObjType, View as View
from typing import Any, Type, TypeVar

V = TypeVar('V', bound=View)

class OperationNotSupported(Exception): ...
BoolV = TypeVar('BoolV', bound='boolean')

class boolean(int, BasicView):
def encode_bytes(self) -> bytes: ...
def __new__(cls: Any, value: int) -> Any: ...
def __add__(self, other: Any) -> None: ...
def __sub__(self, other: Any) -> None: ...
def __mul__(self, other: Any) -> None: ...
def __floordiv__(self, other: Any) -> None: ...
def __truediv__(self, other: Any) -> None: ...
def __bool__(self): ...
@classmethod
def coerce_view(cls: Type[BoolV], v: Any) -> BoolV: ...
@classmethod
def type_byte_length(cls: Any) -> int: ...
@classmethod
def decode_bytes(cls: Type[BoolV], bytez: bytes) -> BoolV: ...
@classmethod
def from_obj(cls: Type[BoolV], obj: ObjType) -> BoolV: ...
def to_obj(self) -> ObjType: ...
@classmethod
def type_repr(cls: Any) -> str: ...
T = TypeVar('T', bound='uint')
W = TypeVar('W', bound=int)

class uint(int, BasicView):
def __new__(cls: Any, value: int) -> Any: ...
def __add__(self, other: int) -> T: ...
def __radd__(self, other: int) -> T: ...
def __sub__(self, other: int) -> T: ...
def __rsub__(self, other: int) -> T: ...
def __mul__(self, other: Any): ...
def __rmul__(self, other: Any): ...
def __mod__(self, other: int) -> T: ...
def __rmod__(self, other: int) -> T: ...
def __floordiv__(self, other: int) -> T: ...
def __rfloordiv__(self, other: int) -> T: ...
def __truediv__(self, other: Any) -> None: ...
def __rtruediv__(self, other: Any) -> None: ...
def __pow__(self, other: int, modulo: Any=...) -> T: ...
def __rpow__(self, other: Any, modulo: Any=...) -> T: ...
def __lshift__(self, other: int) -> T: ...
def __rlshift__(self, other: W) -> W: ...
def __rshift__(self, other: int) -> T: ...
def __rrshift__(self, other: W) -> W: ...
def __and__(self, other: int) -> T: ...
def __rand__(self, other: int) -> T: ...
def __xor__(self, other: int) -> T: ...
def __rxor__(self, other: int) -> T: ...
def __or__(self, other: int) -> T: ...
def __ror__(self, other: int) -> T: ...
def __neg__(self) -> None: ...
def __invert__(self) -> T: ...
def __pos__(self) -> T: ...
def __abs__(self) -> T: ...
@classmethod
def coerce_view(cls: Type[T], v: Any) -> T: ...
@classmethod
def decode_bytes(cls: Type[T], bytez: bytes) -> T: ...
def encode_bytes(self) -> bytes: ...
@classmethod
def from_obj(cls: Type[T], obj: ObjType) -> T: ...
def to_obj(self) -> ObjType: ...
@classmethod
def type_repr(cls: Any) -> str: ...

class uint8(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...

class uint16(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...

class uint32(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...

class uint64(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...

class uint128(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...
def to_obj(self) -> ObjType: ...

class uint256(uint):
@classmethod
def type_byte_length(cls: Any) -> int: ...
def to_obj(self) -> ObjType: ...

class bit(boolean): ...
class byte(uint8): ...
88 changes: 88 additions & 0 deletions mypy_stubs/remerkleable/bitfields.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from collections.abc import Sequence as ColSequence
from remerkleable.basic import boolean as boolean, uint256 as uint256
from remerkleable.core import BackedView as BackedView, FixedByteLengthViewHelper as FixedByteLengthViewHelper, ObjParseException as ObjParseException, ObjType as ObjType, View as View, pack_bits_to_chunks as pack_bits_to_chunks
from remerkleable.readonly_iters import BitfieldIter as BitfieldIter
from remerkleable.tree import Gindex as Gindex, Link as Link, NavigationError as NavigationError, Node as Node, PairNode as PairNode, Root as Root, RootNode as RootNode, get_depth as get_depth, subtree_fill_to_contents as subtree_fill_to_contents, subtree_fill_to_length as subtree_fill_to_length, to_gindex as to_gindex, zero_node as zero_node
from typing import Any, BinaryIO, Type, TypeVar

V = TypeVar('V', bound=View)

class BitsView(BackedView, ColSequence):
@classmethod
def coerce_view(cls: Type[V], v: Any) -> V: ...
@classmethod
def tree_depth(cls: Any) -> int: ...
def length(self) -> int: ...
def get(self, i: int) -> boolean: ...
def set(self, i: int, v: boolean) -> None: ...
def __len__(self): ...
def __getitem__(self, k: Any): ...
def __setitem__(self, k: Any, v: Any) -> None: ...
def encode_bytes(self) -> bytes: ...
@classmethod
def decode_bytes(cls: Type[V], bytez: bytes) -> V: ...
@classmethod
def from_obj(cls: Type[V], obj: ObjType) -> V: ...
def to_obj(self) -> ObjType: ...
def navigate_view(self, key: Any) -> View: ...

class Bitlist(BitsView):
def __new__(cls, *args: Any, **kwargs: Any): ...
def __class_getitem__(cls: Any, limit: Any) -> Type[Bitlist]: ...
def __iter__(self) -> Any: ...
@classmethod
def contents_depth(cls: Any) -> int: ...
@classmethod
def tree_depth(cls: Any) -> int: ...
@classmethod
def limit(cls: Any) -> int: ...
@classmethod
def default_node(cls: Any) -> Node: ...
@classmethod
def type_repr(cls: Any) -> str: ...
@classmethod
def is_fixed_byte_length(cls: Any) -> bool: ...
@classmethod
def min_byte_length(cls: Any) -> int: ...
@classmethod
def max_byte_length(cls: Any) -> int: ...
def length(self) -> int: ...
def append(self, v: boolean) -> Any: ...
def pop(self) -> None: ...
def get(self, i: int) -> boolean: ...
def set(self, i: int, v: boolean) -> None: ...
def value_byte_length(self) -> int: ...
@classmethod
def decode_bytes(cls: Type[V], bytez: bytes) -> V: ...
@classmethod
def deserialize(cls: Type[V], stream: BinaryIO, scope: int) -> V: ...
def serialize(self, stream: BinaryIO) -> int: ...
@classmethod
def navigate_type(cls: Any, key: Any) -> Type[View]: ...
@classmethod
def key_to_static_gindex(cls: Any, key: Any) -> Gindex: ...

class Bitvector(BitsView, FixedByteLengthViewHelper):
def __new__(cls, *args: Any, **kwargs: Any): ...
def __class_getitem__(cls: Any, length: Any) -> Type[Bitvector]: ...
def __iter__(self) -> Any: ...
@classmethod
def tree_depth(cls: Any) -> int: ...
@classmethod
def vector_length(cls: Any) -> int: ...
@classmethod
def default_node(cls: Any) -> Node: ...
@classmethod
def type_repr(cls: Any) -> str: ...
@classmethod
def type_byte_length(cls: Any) -> int: ...
def length(self) -> int: ...
def get(self, i: int) -> boolean: ...
def set(self, i: int, v: boolean) -> None: ...
@classmethod
def deserialize(cls: Type[V], stream: BinaryIO, scope: int) -> V: ...
def serialize(self, stream: BinaryIO) -> int: ...
@classmethod
def navigate_type(cls: Any, key: Any) -> Type[View]: ...
@classmethod
def key_to_static_gindex(cls: Any, key: Any) -> Gindex: ...
81 changes: 81 additions & 0 deletions mypy_stubs/remerkleable/byte_arrays.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from remerkleable.basic import byte as byte, uint256 as uint256
from remerkleable.core import FixedByteLengthViewHelper as FixedByteLengthViewHelper, ObjParseException as ObjParseException, ObjType as ObjType, View as View, ViewHook as ViewHook, pack_bytes_to_chunks as pack_bytes_to_chunks, zero_node as zero_node
from remerkleable.tree import Gindex as Gindex, Node as Node, PairNode as PairNode, Root as Root, RootNode as RootNode, get_depth as get_depth, subtree_fill_to_contents as subtree_fill_to_contents, subtree_fill_to_length as subtree_fill_to_length, to_gindex as to_gindex
from typing import Any, BinaryIO, Optional, Type, TypeVar

RV = TypeVar('RV', bound='RawBytesView')

class RawBytesView(bytes, View):
def __new__(cls, *args: Any, **kwargs: Any): ...
@classmethod
def default_bytes(cls: Any) -> bytes: ...
@classmethod
def coerce_view(cls: Type[RV], v: Any) -> RV: ...
@classmethod
def tree_depth(cls: Any) -> int: ...
def set_backing(self, value: Any) -> None: ...
@classmethod
def decode_bytes(cls: Type[RV], bytez: bytes) -> RV: ...
def encode_bytes(self) -> bytes: ...
@classmethod
def from_obj(cls: Type[RV], obj: ObjType) -> RV: ...
def to_obj(self) -> ObjType: ...
def navigate_view(self, key: Any) -> View: ...
BV = TypeVar('BV', bound='ByteVector')

class ByteVector(RawBytesView, FixedByteLengthViewHelper, View):
def __new__(cls, *args: Any, **kwargs: Any): ...
def __class_getitem__(cls: Any, length: Any) -> Type[ByteVector]: ...
@classmethod
def vector_length(cls): ...
@classmethod
def default_bytes(cls: Any) -> bytes: ...
@classmethod
def type_repr(cls: Any) -> str: ...
@classmethod
def view_from_backing(cls: Type[BV], node: Node, hook: Optional[ViewHook]=...) -> BV: ...
def get_backing(self) -> Node: ...
@classmethod
def navigate_type(cls: Any, key: Any) -> Type[View]: ...
@classmethod
def key_to_static_gindex(cls: Any, key: Any) -> Gindex: ...

Bytes1: Any
Bytes4: Any
Bytes8: Any
Bytes32: Any
Bytes48: Any
Bytes96: Any
BL = TypeVar('BL', bound='ByteList')

class ByteList(RawBytesView, FixedByteLengthViewHelper, View):
def __new__(cls, *args: Any, **kwargs: Any): ...
def __class_getitem__(cls: Any, limit: Any) -> Type[ByteList]: ...
@classmethod
def limit(cls: Any) -> int: ...
@classmethod
def default_bytes(cls: Any) -> bytes: ...
@classmethod
def type_repr(cls: Any) -> str: ...
@classmethod
def view_from_backing(cls: Type[BL], node: Node, hook: Optional[ViewHook]=...) -> BL: ...
def get_backing(self) -> Node: ...
@classmethod
def contents_depth(cls: Any) -> int: ...
@classmethod
def tree_depth(cls: Any) -> int: ...
@classmethod
def default_node(cls: Any) -> Node: ...
@classmethod
def navigate_type(cls: Any, key: Any) -> Type[View]: ...
@classmethod
def key_to_static_gindex(cls: Any, key: Any) -> Gindex: ...
@classmethod
def is_fixed_byte_length(cls: Any) -> bool: ...
@classmethod
def min_byte_length(cls: Any) -> int: ...
@classmethod
def max_byte_length(cls: Any) -> int: ...
@classmethod
def deserialize(cls: Type[BL], stream: BinaryIO, scope: int) -> BL: ...
def value_byte_length(self) -> int: ...
Loading