From e873bbd73bc3d05526b3c3f42ea3e1bd88049eb9 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sat, 22 Jun 2019 19:59:15 +0200 Subject: [PATCH] support list casting --- test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py | 2 +- test_libs/pyspec/eth2spec/utils/ssz/test_ssz_typing.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 14415ac6b..891480a5c 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -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 diff --git a/test_libs/pyspec/eth2spec/utils/ssz/test_ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/test_ssz_typing.py index 4325501aa..bd86a5806 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/test_ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/test_ssz_typing.py @@ -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