From 2d6771707925558b54fc5fe6bbc8154198dca2fd Mon Sep 17 00:00:00 2001 From: protolambda Date: Thu, 20 Jun 2019 21:42:55 +0200 Subject: [PATCH] fix linting issues + make spec builder remove comments in container re-initialization part --- scripts/build_spec.py | 15 ++++++++++++++- specs/core/0_beacon-chain.md | 5 +++-- test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index d33ba6642..338093e94 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -106,6 +106,18 @@ def apply_constants_preset(preset: Dict[str, Any]) -> None: ''' +def strip_comments(raw: str) -> str: + comment_line_regex = re.compile('^\s+# ') + lines = raw.split('\n') + out = [] + for line in lines: + if not comment_line_regex.match(line): + if ' #' in line: + line = line[:line.index(' #')] + out.append(line) + return '\n'.join(out) + + def objects_to_spec(functions: Dict[str, str], custom_types: Dict[str, str], constants: Dict[str, str], @@ -133,7 +145,8 @@ def objects_to_spec(functions: Dict[str, str], ssz_objects_instantiation_spec = '\n\n'.join(ssz_objects.values()) ssz_objects_reinitialization_spec = ( 'def init_SSZ_types() -> None:\n global_vars = globals()\n\n ' - + '\n\n '.join([re.sub(r'(?!\n\n)\n', r'\n ', value[:-1]) for value in ssz_objects.values()]) + + '\n\n '.join([strip_comments(re.sub(r'(?!\n\n)\n', r'\n ', value[:-1])) + for value in ssz_objects.values()]) + '\n\n' + '\n'.join(map(lambda x: ' global_vars[\'%s\'] = %s' % (x, x), ssz_objects.keys())) ) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 9c871f5f2..52d087281 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -533,7 +533,7 @@ class BeaconState(Container): randao_mixes: Vector[Hash, EPOCHS_PER_HISTORICAL_VECTOR] active_index_roots: Vector[Hash, EPOCHS_PER_HISTORICAL_VECTOR] # Digests of the active registry, for light clients # Slashings - slashed_balances: Vector[Gwei, EPOCHS_PER_SLASHED_BALANCES_VECTOR] # Sums of the effective balances of slashed validators + slashed_balances: Vector[Gwei, EPOCHS_PER_SLASHED_BALANCES_VECTOR] # Sums of the slashed effective balances # Attestations previous_epoch_attestations: List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH] current_epoch_attestations: List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH] @@ -1525,7 +1525,8 @@ def process_slashings(state: BeaconState) -> None: total_penalties = total_at_end - total_at_start for index, validator in enumerate(state.validators): - if validator.slashed and current_epoch == validator.withdrawable_epoch - EPOCHS_PER_SLASHED_BALANCES_VECTOR // 2: + if validator.slashed and current_epoch == ( + validator.withdrawable_epoch - EPOCHS_PER_SLASHED_BALANCES_VECTOR // 2): penalty = max( validator.effective_balance * min(total_penalties * 3, total_balance) // total_balance, validator.effective_balance // MIN_SLASHING_PENALTY_QUOTIENT diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 39fed9ac8..c9516bebf 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -319,7 +319,7 @@ class BaseList(list, Elements): def last(self): # be explict about getting the last item, for the non-python readers, and negative-index safety - return self[len(self)-1] + return self[len(self) - 1] class List(BaseList):