support list casting

This commit is contained in:
protolambda 2019-06-22 19:59:15 +02:00
parent dd5ad2e2c5
commit e873bbd73b
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
2 changed files with 3 additions and 1 deletions

View File

@ -296,7 +296,7 @@ class BaseList(list, Elements):
@classmethod
def extract_args(cls, *args):
x = list(args)
if len(x) == 1 and isinstance(x[0], GeneratorType):
if len(x) == 1 and isinstance(x[0], (GeneratorType, list, tuple)):
x = list(x[0])
x = [coerce_type_maybe(v, cls.elem_type) for v in x]
return x

View File

@ -161,6 +161,8 @@ def test_list():
assert issubclass(v.type(), Elements)
assert isinstance(v.type(), ElementsType)
assert len(typ([i for i in range(10)])) == 10 # cast py list to SSZ list
foo = List[uint32, 128](0 for i in range(128))
foo[0] = 123
foo[1] = 654