From dece5f4de2fb66df75ad0803a0295d3055b03907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Tue, 21 Dec 2021 15:26:54 +0100 Subject: [PATCH] pylint: Enable and fix redefined-builtin warnings --- docs/conf.py | 2 +- .../endToEndExtraction/remove-testcases.py | 4 +- .../endToEndExtraction/verify-testcases.py | 36 ++++++------ scripts/error_codes.py | 56 +++++++++---------- scripts/isolate_tests.py | 4 +- scripts/pylintrc | 3 +- .../docker-scripts/isolate_tests.py | 4 +- 7 files changed, 54 insertions(+), 55 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4ae4812c5..10aa406f2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,7 +63,7 @@ master_doc = 'index' # General information about the project. project = 'Solidity' -copyright = '2016-2021, Ethereum' +project_copyright = '2016-2021, Ethereum' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/scripts/endToEndExtraction/remove-testcases.py b/scripts/endToEndExtraction/remove-testcases.py index 28822e044..ca9a63599 100755 --- a/scripts/endToEndExtraction/remove-testcases.py +++ b/scripts/endToEndExtraction/remove-testcases.py @@ -33,12 +33,12 @@ def parse_call(call): return function.strip(), arguments.strip(), results.strip() -def colorize(left, right, id): +def colorize(left, right, index): red = "\x1b[31m" yellow = "\x1b[33m" reset = "\x1b[0m" colors = [red, yellow] - color = colors[id % len(colors)] + color = colors[index % len(colors)] function, _arguments, _results = parse_call(right) left = left.replace("compileAndRun", color + "compileAndRun" + reset) right = right.replace("constructor", color + "constructor" + reset) diff --git a/scripts/endToEndExtraction/verify-testcases.py b/scripts/endToEndExtraction/verify-testcases.py index 150a1806b..87d608607 100755 --- a/scripts/endToEndExtraction/verify-testcases.py +++ b/scripts/endToEndExtraction/verify-testcases.py @@ -32,11 +32,11 @@ class Trace: def get_input(self): return self._input - def set_input(self, input): + def set_input(self, bytecode): if self.kind == "create": # remove cbor encoded metadata from bytecode - length = int(input[-4:], 16) * 2 - self._input = input[:len(input) - length - 4] + length = int(bytecode[-4:], 16) * 2 + self._input = bytecode[:len(bytecode) - length - 4] def get_output(self): return self._output @@ -110,21 +110,21 @@ class TraceAnalyser: @staticmethod def parse_parameters(line, trace): - input = re.search(r'\s*in:\s*([a-fA-F0-9]*)', line, re.M | re.I) - if input: - trace.input = input.group(1) - output = re.search(r'\s*out:\s*([a-fA-F0-9]*)', line, re.M | re.I) - if output: - trace.output = output.group(1) - result = re.search(r'\s*result:\s*([a-fA-F0-9]*)', line, re.M | re.I) - if result: - trace.result = result.group(1) - gas_used = re.search(r'\s*gas\sused:\s*([a-fA-F0-9]*)', line, re.M | re.I) - if gas_used: - trace.gas = gas_used.group(1) - value = re.search(r'\s*value:\s*([a-fA-F0-9]*)', line, re.M | re.I) - if value: - trace.value = value.group(1) + input_match = re.search(r'\s*in:\s*([a-fA-F0-9]*)', line, re.M | re.I) + if input_match: + trace.input = input_match.group(1) + output_match = re.search(r'\s*out:\s*([a-fA-F0-9]*)', line, re.M | re.I) + if output_match: + trace.output = output_match.group(1) + result_match = re.search(r'\s*result:\s*([a-fA-F0-9]*)', line, re.M | re.I) + if result_match: + trace.result = result_match.group(1) + gas_used_match = re.search(r'\s*gas\sused:\s*([a-fA-F0-9]*)', line, re.M | re.I) + if gas_used_match: + trace.gas = gas_used_match.group(1) + value_match = re.search(r'\s*value:\s*([a-fA-F0-9]*)', line, re.M | re.I) + if value_match: + trace.value = value_match.group(1) def diff(self, analyser): if not self.ready: diff --git a/scripts/error_codes.py b/scripts/error_codes.py index 402068d14..a50e34d0b 100755 --- a/scripts/error_codes.py +++ b/scripts/error_codes.py @@ -44,11 +44,11 @@ def find_ids_in_source_file(file_name, id_to_file_names): if in_comment(source, m.start()): continue underscore_pos = m.group(0).index("_") - id = m.group(0)[0:underscore_pos] - if id in id_to_file_names: - id_to_file_names[id].append(file_name) + error_id = m.group(0)[0:underscore_pos] + if error_id in id_to_file_names: + id_to_file_names[error_id].append(file_name) else: - id_to_file_names[id] = [file_name] + id_to_file_names[error_id] = [file_name] def find_ids_in_source_files(file_names): @@ -76,16 +76,16 @@ def fix_ids_in_source_file(file_name, id_to_count, available_ids): destination.extend(source[k:m.start()]) underscore_pos = m.group(0).index("_") - id = m.group(0)[0:underscore_pos] + error_id = m.group(0)[0:underscore_pos] # incorrect id or id has a duplicate somewhere - if not in_comment(source, m.start()) and (len(id) != 4 or id[0] == "0" or id_to_count[id] > 1): - assert id in id_to_count + if not in_comment(source, m.start()) and (len(error_id) != 4 or error_id[0] == "0" or id_to_count[error_id] > 1): + assert error_id in id_to_count new_id = get_next_id(available_ids) assert new_id not in id_to_count - id_to_count[id] -= 1 + id_to_count[error_id] -= 1 else: - new_id = id + new_id = error_id destination.extend(new_id + "_error") k = m.end() @@ -104,7 +104,7 @@ def fix_ids_in_source_files(file_names, id_to_count): id_to_count contains number of appearances of every id in sources """ - available_ids = {str(id) for id in range(1000, 10000)} - id_to_count.keys() + available_ids = {str(error_id) for error_id in range(1000, 10000)} - id_to_count.keys() for file_name in file_names: fix_ids_in_source_file(file_name, id_to_count, available_ids) @@ -113,8 +113,8 @@ def find_files(top_dir, sub_dirs, extensions): """Builds a list of files with given extensions in specified subdirectories""" source_file_names = [] - for dir in sub_dirs: - for root, _, file_names in os.walk(os.path.join(top_dir, dir), onerror=lambda e: exit(f"Walk error: {e}")): + for directory in sub_dirs: + for root, _, file_names in os.walk(os.path.join(top_dir, directory), onerror=lambda e: sys.exit(f"Walk error: {e}")): for file_name in file_names: _, ext = path.splitext(file_name) if ext in extensions: @@ -145,27 +145,27 @@ def find_ids_in_cmdline_test_err(file_name): def print_ids(ids): - for k, id in enumerate(sorted(ids)): + for k, error_id in enumerate(sorted(ids)): if k % 10 > 0: print(" ", end="") elif k > 0: print() - print(id, end="") + print(error_id, end="") def print_ids_per_file(ids, id_to_file_names, top_dir): file_name_to_ids = {} - for id in ids: - for file_name in id_to_file_names[id]: + for error_id in ids: + for file_name in id_to_file_names[error_id]: relpath = path.relpath(file_name, top_dir) if relpath not in file_name_to_ids: file_name_to_ids[relpath] = [] - file_name_to_ids[relpath].append(id) + file_name_to_ids[relpath].append(error_id) for file_name in sorted(file_name_to_ids): print(file_name) - for id in sorted(file_name_to_ids[file_name]): - print(f" {id}", end="") + for error_id in sorted(file_name_to_ids[file_name]): + print(f" {error_id}", end="") print() @@ -289,15 +289,15 @@ def main(argv): source_id_to_file_names = find_ids_in_source_files(source_file_names) ok = True - for id in sorted(source_id_to_file_names): - if len(id) != 4: - print(f"ID {id} length != 4") + for error_id in sorted(source_id_to_file_names): + if len(error_id) != 4: + print(f"ID {error_id} length != 4") ok = False - if id[0] == "0": - print(f"ID {id} starts with zero") + if error_id[0] == "0": + print(f"ID {error_id} starts with zero") ok = False - if len(source_id_to_file_names[id]) > 1: - print(f"ID {id} appears {len(source_id_to_file_names[id])} times") + if len(source_id_to_file_names[error_id]) > 1: + print(f"ID {error_id} appears {len(source_id_to_file_names[error_id])} times") ok = False if examine_coverage: @@ -315,7 +315,7 @@ def main(argv): if not ok: print("Incorrect IDs have to be fixed before applying --next") sys.exit(1) - available_ids = {str(id) for id in range(1000, 10000)} - source_id_to_file_names.keys() + available_ids = {str(error_id) for error_id in range(1000, 10000)} - source_id_to_file_names.keys() next_id = get_next_id(available_ids) print(f"Next ID: {next_id}") sys.exit(0) @@ -341,7 +341,7 @@ def main(argv): sys.exit(1) # number of appearances for every id - source_id_to_count = { id: len(file_names) for id, file_names in source_id_to_file_names.items() } + source_id_to_count = { error_id: len(file_names) for error_id, file_names in source_id_to_file_names.items() } fix_ids_in_source_files(source_file_names, source_id_to_count) print("Fixing completed") diff --git a/scripts/isolate_tests.py b/scripts/isolate_tests.py index 4abe6a0bd..e641d58d1 100755 --- a/scripts/isolate_tests.py +++ b/scripts/isolate_tests.py @@ -106,8 +106,8 @@ def write_cases(f, solidityTests, yulTests): # When code examples are extracted they are indented by 8 spaces, which violates the style guide, # so before checking remove 4 spaces from each line. remainder = dedent(test) - hash = hashlib.sha256(test.encode("utf-8")).hexdigest() - sol_filename = f'test_{hash}_{cleaned_filename}.{language}' + source_code_hash = hashlib.sha256(test.encode("utf-8")).hexdigest() + sol_filename = f'test_{source_code_hash}_{cleaned_filename}.{language}' with open(sol_filename, mode='w', encoding='utf8', newline='') as fi: fi.write(remainder) diff --git a/scripts/pylintrc b/scripts/pylintrc index 6835806b6..e14763c0d 100644 --- a/scripts/pylintrc +++ b/scripts/pylintrc @@ -14,7 +14,7 @@ # ATTENTION: This list should be extended with care, consider using NOLINT comments inside your # python files instead, as the goal is actually to reduce the list of globally disabled checks. # -# TODO: What could be eliminated in future PRs: bad-continuation, invalid-name, redefined-builtin, +# TODO: What could be eliminated in future PRs: bad-continuation, invalid-name, # undefined-variable, unused-*, useless-object-inheritance. disable= bad-continuation, @@ -25,7 +25,6 @@ disable= missing-docstring, no-else-return, pointless-string-statement, - redefined-builtin, redefined-outer-name, too-few-public-methods, too-many-public-methods, diff --git a/scripts/wasm-rebuild/docker-scripts/isolate_tests.py b/scripts/wasm-rebuild/docker-scripts/isolate_tests.py index c447c1e67..41487325e 100755 --- a/scripts/wasm-rebuild/docker-scripts/isolate_tests.py +++ b/scripts/wasm-rebuild/docker-scripts/isolate_tests.py @@ -47,8 +47,8 @@ def write_cases(f, tests): cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower() for test in tests: remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE) - hash = hashlib.sha256(test).hexdigest() - with open(f'test_{hash}_{cleaned_filename}.sol', 'w', encoding='utf8') as _f: + source_code_hash = hashlib.sha256(test).hexdigest() + with open(f'test_{source_code_hash}_{cleaned_filename}.sol', 'w', encoding='utf8') as _f: _f.write(remainder)