Fix linting errors

This commit is contained in:
Dankrad Feist 2019-06-27 10:42:14 +01:00
parent 23c743570e
commit 494984f7d3
No known key found for this signature in database
GPG Key ID: 6815E6A20BEBBABA
3 changed files with 14 additions and 6 deletions

View File

@ -26,7 +26,7 @@ def serialize_basic(value: SSZValue):
def deserialize_basic(value, typ: BasicType):
if issubclass(typ, uint):
return typ(int.from_bytes(value, 'little'))
elif issubclass(typ, Bool):
elif issubclass(typ, boolean):
assert value in (b'\x00', b'\x01')
return typ(value == b'\x01')
else:

View File

@ -280,12 +280,15 @@ class ElementsType(ParamsMeta):
elem_type: SSZType
length: int
class BitElementsType(ElementsType):
elem_type = boolean
class Elements(ParamsBase, metaclass=ElementsType):
pass
class BaseList(list, Elements):
def __init__(self, *args):
@ -342,12 +345,15 @@ class BaseList(list, Elements):
# be explict about getting the last item, for the non-python readers, and negative-index safety
return self[len(self) - 1]
class BaseBitfield(BaseList, metaclass=BitElementsType):
elem_type = bool
class Bitlist(BaseBitfield):
pass
class Bitvector(BaseBitfield):
pass

View File

@ -81,8 +81,10 @@ test_data = [
("boolean T", boolean(True), "01", chunk("01")),
("bitvector TFTFFFTTFT", Bitvector[10](1, 0, 1, 0, 0, 0, 1, 1, 0, 1), "c502", chunk("c502")),
("bitlist TFTFFFTTFT", Bitlist[16](1, 0, 1, 0, 0, 0, 1, 1, 0, 1), "c506", h(chunk("c502"), chunk("0A"))),
("bitvector TFTFFFTTFTFFFFTT", Bitvector[16](1,0,1,0,0,0,1,1,0,1,0,0,0,0,1,1), "c5c2", chunk("c5c2")),
("bitlist TFTFFFTTFTFFFFTT", Bitlist[16](1,0,1,0,0,0,1,1,0,1,0,0,0,0,1,1), "c5c201", h(chunk("c5c2"), chunk("10"))),
("bitvector TFTFFFTTFTFFFFTT", Bitvector[16](1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1),
"c5c2", chunk("c5c2")),
("bitlist TFTFFFTTFTFFFFTT", Bitlist[16](1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1),
"c5c201", h(chunk("c5c2"), chunk("10"))),
("uint8 00", uint8(0x00), "00", chunk("00")),
("uint8 01", uint8(0x01), "01", chunk("01")),
("uint8 ab", uint8(0xab), "ab", chunk("ab")),