mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-02 13:14:59 -05:00
support list casting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user