fix linting + mypy

This commit is contained in:
protolambda 2019-06-19 01:03:04 +02:00
parent 4b4bf87e47
commit 5be0c57aad
5 changed files with 28 additions and 20 deletions

View File

@ -20,8 +20,8 @@ from eth2spec.utils.ssz.ssz_impl import (
signing_root,
)
from eth2spec.utils.ssz.ssz_typing import (
# unused: uint8, uint16, uint32, uint128, uint256,
Bit, Container, List, Vector, Bytes, BytesN, uint64
Bit, Container, List, Vector, Bytes, uint64,
Bytes4, Bytes32, Bytes48, Bytes96,
)
from eth2spec.utils.bls import (
bls_aggregate_pubkeys,
@ -45,7 +45,7 @@ from eth2spec.utils.ssz.ssz_impl import (
is_empty,
)
from eth2spec.utils.ssz.ssz_typing import (
Bit, Container, List, Vector, Bytes, BytesN, uint64,
Bit, Container, List, Vector, Bytes, uint64,
Bytes4, Bytes32, Bytes48, Bytes96,
)
from eth2spec.utils.bls import (

View File

@ -1,7 +1,7 @@
from ..merkle_minimal import merkleize_chunks
from ..hash_function import hash
from .ssz_typing import (
SSZValue, SSZType, BasicValue, BasicType, Series, ElementsType, Elements, Bit, Container, List, Vector, Bytes, BytesN, uint
SSZValue, SSZType, BasicValue, BasicType, Series, Elements, Bit, Container, List, Bytes, BytesN, uint
)
# SSZ Serialization

View File

@ -400,3 +400,10 @@ class BytesN(BytesLike):
@classmethod
def is_fixed_size(cls):
return True
# Helpers for common BytesN types.
Bytes4 = BytesN[4]
Bytes32 = BytesN[32]
Bytes48 = BytesN[48]
Bytes96 = BytesN[96]

View File

@ -1,7 +1,7 @@
from .ssz_impl import serialize, serialize_basic, encode_series, signing_root, hash_tree_root
from .ssz_impl import serialize, hash_tree_root
from .ssz_typing import (
SSZValue, SSZType, BasicValue, BasicType, Series, ElementsType, Bit, Container, List, Vector, Bytes, BytesN,
uint, uint8, uint16, uint32, uint64, uint128, uint256, byte
Bit, Container, List, Vector, Bytes, BytesN,
uint8, uint16, uint32, uint64, byte
)
import pytest

View File

@ -1,5 +1,6 @@
from .ssz_typing import (
SSZValue, SSZType, BasicValue, BasicType, Series, ElementsType, Elements, Bit, Container, List, Vector, Bytes, BytesN,
SSZValue, SSZType, BasicValue, BasicType, Series, ElementsType,
Elements, Bit, Container, List, Vector, Bytes, BytesN,
uint, uint8, uint16, uint32, uint64, uint128, uint256
)
@ -41,13 +42,13 @@ def test_basic_instances():
def test_basic_value_bounds():
max = {
Bit: 2**1,
uint8: 2**(8 * 1),
uint16: 2**(8 * 2),
uint32: 2**(8 * 4),
uint64: 2**(8 * 8),
uint128: 2**(8 * 16),
uint256: 2**(8 * 32),
Bit: 2 ** 1,
uint8: 2 ** (8 * 1),
uint16: 2 ** (8 * 2),
uint32: 2 ** (8 * 4),
uint64: 2 ** (8 * 8),
uint128: 2 ** (8 * 16),
uint256: 2 ** (8 * 32),
}
for k, v in max.items():
# this should work
@ -161,12 +162,12 @@ def test_list():
foo[127] = 222
assert sum(foo) == 999
try:
foo[3] = 2**32 # out of bounds
foo[3] = 2 ** 32 # out of bounds
except ValueError:
pass
try:
foo[3] = uint64(2**32 - 1) # within bounds, wrong type
foo[3] = uint64(2 ** 32 - 1) # within bounds, wrong type
assert False
except ValueError:
pass