From e1343f99bbff2054a89e06a3b6d904ec7c3519d7 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 9 May 2019 14:29:21 +0800 Subject: [PATCH] Fix pyspec/eth2spec/debug lint --- test_libs/pyspec/eth2spec/debug/decode.py | 4 ++-- test_libs/pyspec/eth2spec/debug/encode.py | 1 - .../pyspec/eth2spec/debug/random_value.py | 23 +++++++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test_libs/pyspec/eth2spec/debug/decode.py b/test_libs/pyspec/eth2spec/debug/decode.py index aeac3924d..e9aa8bc2b 100644 --- a/test_libs/pyspec/eth2spec/debug/decode.py +++ b/test_libs/pyspec/eth2spec/debug/decode.py @@ -16,11 +16,11 @@ def decode(json, typ): for field, subtype in typ.fields.items(): temp[field] = decode(json[field], subtype) if field + "_hash_tree_root" in json: - assert(json[field + "_hash_tree_root"][2:] == + assert(json[field + "_hash_tree_root"][2:] == hash_tree_root(temp[field], subtype).hex()) ret = typ(**temp) if "hash_tree_root" in json: - assert(json["hash_tree_root"][2:] == + assert(json["hash_tree_root"][2:] == hash_tree_root(ret, typ).hex()) return ret else: diff --git a/test_libs/pyspec/eth2spec/debug/encode.py b/test_libs/pyspec/eth2spec/debug/encode.py index d3513e638..b38e5fe98 100644 --- a/test_libs/pyspec/eth2spec/debug/encode.py +++ b/test_libs/pyspec/eth2spec/debug/encode.py @@ -25,4 +25,3 @@ def encode(value, typ, include_hash_tree_roots=False): else: print(value, typ) raise Exception("Type not recognized") - diff --git a/test_libs/pyspec/eth2spec/debug/random_value.py b/test_libs/pyspec/eth2spec/debug/random_value.py index a853d2328..f28181943 100644 --- a/test_libs/pyspec/eth2spec/debug/random_value.py +++ b/test_libs/pyspec/eth2spec/debug/random_value.py @@ -31,7 +31,12 @@ class RandomizationMode(Enum): return self.value in [0, 4, 5] -def get_random_ssz_object(rng: Random, typ: Any, max_bytes_length: int, max_list_length: int, mode: RandomizationMode, chaos: bool) -> Any: +def get_random_ssz_object(rng: Random, + typ: Any, + max_bytes_length: int, + max_list_length: int, + mode: RandomizationMode, + chaos: bool) -> Any: """ Create an object for a given type, filled with random data. :param rng: The random number generator to use. @@ -77,7 +82,10 @@ def get_random_ssz_object(rng: Random, typ: Any, max_bytes_length: int, max_list return get_random_basic_value(rng, typ) # Vector: elif isinstance(typ, list) and len(typ) == 2: - return [get_random_ssz_object(rng, typ[0], max_bytes_length, max_list_length, mode, chaos) for _ in range(typ[1])] + return [ + get_random_ssz_object(rng, typ[0], max_bytes_length, max_list_length, mode, chaos) + for _ in range(typ[1]) + ] # List: elif isinstance(typ, list) and len(typ) == 1: length = rng.randint(0, max_list_length) @@ -85,10 +93,17 @@ def get_random_ssz_object(rng: Random, typ: Any, max_bytes_length: int, max_list length = 1 if mode == RandomizationMode.mode_max_count: length = max_list_length - return [get_random_ssz_object(rng, typ[0], max_bytes_length, max_list_length, mode, chaos) for _ in range(length)] + return [ + get_random_ssz_object(rng, typ[0], max_bytes_length, max_list_length, mode, chaos) + for _ in range(length) + ] # Container: elif hasattr(typ, 'fields'): - return typ(**{field: get_random_ssz_object(rng, subtype, max_bytes_length, max_list_length, mode, chaos) for field, subtype in typ.fields.items()}) + return typ(**{ + field: + get_random_ssz_object(rng, subtype, max_bytes_length, max_list_length, mode, chaos) + for field, subtype in typ.fields.items() + }) else: print(typ) raise Exception("Type not recognized")