Skip to content

Commit dece5f4

Browse files
committed
pylint: Enable and fix redefined-builtin warnings
1 parent 5b10ff1 commit dece5f4

File tree

7 files changed

+54
-55
lines changed

7 files changed

+54
-55
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def setup(sphinx):
6363

6464
# General information about the project.
6565
project = 'Solidity'
66-
copyright = '2016-2021, Ethereum'
66+
project_copyright = '2016-2021, Ethereum'
6767

6868
# The version info for the project you're documenting, acts as replacement for
6969
# |version| and |release|, also used in various other places throughout the

scripts/endToEndExtraction/remove-testcases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ def parse_call(call):
3333
return function.strip(), arguments.strip(), results.strip()
3434

3535

36-
def colorize(left, right, id):
36+
def colorize(left, right, index):
3737
red = "\x1b[31m"
3838
yellow = "\x1b[33m"
3939
reset = "\x1b[0m"
4040
colors = [red, yellow]
41-
color = colors[id % len(colors)]
41+
color = colors[index % len(colors)]
4242
function, _arguments, _results = parse_call(right)
4343
left = left.replace("compileAndRun", color + "compileAndRun" + reset)
4444
right = right.replace("constructor", color + "constructor" + reset)

scripts/endToEndExtraction/verify-testcases.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def __init__(self, kind, parameter):
3232
def get_input(self):
3333
return self._input
3434

35-
def set_input(self, input):
35+
def set_input(self, bytecode):
3636
if self.kind == "create":
3737
# remove cbor encoded metadata from bytecode
38-
length = int(input[-4:], 16) * 2
39-
self._input = input[:len(input) - length - 4]
38+
length = int(bytecode[-4:], 16) * 2
39+
self._input = bytecode[:len(bytecode) - length - 4]
4040

4141
def get_output(self):
4242
return self._output
@@ -110,21 +110,21 @@ def analyse(self):
110110

111111
@staticmethod
112112
def parse_parameters(line, trace):
113-
input = re.search(r'\s*in:\s*([a-fA-F0-9]*)', line, re.M | re.I)
114-
if input:
115-
trace.input = input.group(1)
116-
output = re.search(r'\s*out:\s*([a-fA-F0-9]*)', line, re.M | re.I)
117-
if output:
118-
trace.output = output.group(1)
119-
result = re.search(r'\s*result:\s*([a-fA-F0-9]*)', line, re.M | re.I)
120-
if result:
121-
trace.result = result.group(1)
122-
gas_used = re.search(r'\s*gas\sused:\s*([a-fA-F0-9]*)', line, re.M | re.I)
123-
if gas_used:
124-
trace.gas = gas_used.group(1)
125-
value = re.search(r'\s*value:\s*([a-fA-F0-9]*)', line, re.M | re.I)
126-
if value:
127-
trace.value = value.group(1)
113+
input_match = re.search(r'\s*in:\s*([a-fA-F0-9]*)', line, re.M | re.I)
114+
if input_match:
115+
trace.input = input_match.group(1)
116+
output_match = re.search(r'\s*out:\s*([a-fA-F0-9]*)', line, re.M | re.I)
117+
if output_match:
118+
trace.output = output_match.group(1)
119+
result_match = re.search(r'\s*result:\s*([a-fA-F0-9]*)', line, re.M | re.I)
120+
if result_match:
121+
trace.result = result_match.group(1)
122+
gas_used_match = re.search(r'\s*gas\sused:\s*([a-fA-F0-9]*)', line, re.M | re.I)
123+
if gas_used_match:
124+
trace.gas = gas_used_match.group(1)
125+
value_match = re.search(r'\s*value:\s*([a-fA-F0-9]*)', line, re.M | re.I)
126+
if value_match:
127+
trace.value = value_match.group(1)
128128

129129
def diff(self, analyser):
130130
if not self.ready:

scripts/error_codes.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def find_ids_in_source_file(file_name, id_to_file_names):
4444
if in_comment(source, m.start()):
4545
continue
4646
underscore_pos = m.group(0).index("_")
47-
id = m.group(0)[0:underscore_pos]
48-
if id in id_to_file_names:
49-
id_to_file_names[id].append(file_name)
47+
error_id = m.group(0)[0:underscore_pos]
48+
if error_id in id_to_file_names:
49+
id_to_file_names[error_id].append(file_name)
5050
else:
51-
id_to_file_names[id] = [file_name]
51+
id_to_file_names[error_id] = [file_name]
5252

5353

5454
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):
7676
destination.extend(source[k:m.start()])
7777

7878
underscore_pos = m.group(0).index("_")
79-
id = m.group(0)[0:underscore_pos]
79+
error_id = m.group(0)[0:underscore_pos]
8080

8181
# incorrect id or id has a duplicate somewhere
82-
if not in_comment(source, m.start()) and (len(id) != 4 or id[0] == "0" or id_to_count[id] > 1):
83-
assert id in id_to_count
82+
if not in_comment(source, m.start()) and (len(error_id) != 4 or error_id[0] == "0" or id_to_count[error_id] > 1):
83+
assert error_id in id_to_count
8484
new_id = get_next_id(available_ids)
8585
assert new_id not in id_to_count
86-
id_to_count[id] -= 1
86+
id_to_count[error_id] -= 1
8787
else:
88-
new_id = id
88+
new_id = error_id
8989

9090
destination.extend(new_id + "_error")
9191
k = m.end()
@@ -104,7 +104,7 @@ def fix_ids_in_source_files(file_names, id_to_count):
104104
id_to_count contains number of appearances of every id in sources
105105
"""
106106

107-
available_ids = {str(id) for id in range(1000, 10000)} - id_to_count.keys()
107+
available_ids = {str(error_id) for error_id in range(1000, 10000)} - id_to_count.keys()
108108
for file_name in file_names:
109109
fix_ids_in_source_file(file_name, id_to_count, available_ids)
110110

@@ -113,8 +113,8 @@ def find_files(top_dir, sub_dirs, extensions):
113113
"""Builds a list of files with given extensions in specified subdirectories"""
114114

115115
source_file_names = []
116-
for dir in sub_dirs:
117-
for root, _, file_names in os.walk(os.path.join(top_dir, dir), onerror=lambda e: exit(f"Walk error: {e}")):
116+
for directory in sub_dirs:
117+
for root, _, file_names in os.walk(os.path.join(top_dir, directory), onerror=lambda e: sys.exit(f"Walk error: {e}")):
118118
for file_name in file_names:
119119
_, ext = path.splitext(file_name)
120120
if ext in extensions:
@@ -145,27 +145,27 @@ def find_ids_in_cmdline_test_err(file_name):
145145

146146

147147
def print_ids(ids):
148-
for k, id in enumerate(sorted(ids)):
148+
for k, error_id in enumerate(sorted(ids)):
149149
if k % 10 > 0:
150150
print(" ", end="")
151151
elif k > 0:
152152
print()
153-
print(id, end="")
153+
print(error_id, end="")
154154

155155

156156
def print_ids_per_file(ids, id_to_file_names, top_dir):
157157
file_name_to_ids = {}
158-
for id in ids:
159-
for file_name in id_to_file_names[id]:
158+
for error_id in ids:
159+
for file_name in id_to_file_names[error_id]:
160160
relpath = path.relpath(file_name, top_dir)
161161
if relpath not in file_name_to_ids:
162162
file_name_to_ids[relpath] = []
163-
file_name_to_ids[relpath].append(id)
163+
file_name_to_ids[relpath].append(error_id)
164164

165165
for file_name in sorted(file_name_to_ids):
166166
print(file_name)
167-
for id in sorted(file_name_to_ids[file_name]):
168-
print(f" {id}", end="")
167+
for error_id in sorted(file_name_to_ids[file_name]):
168+
print(f" {error_id}", end="")
169169
print()
170170

171171

@@ -289,15 +289,15 @@ def main(argv):
289289
source_id_to_file_names = find_ids_in_source_files(source_file_names)
290290

291291
ok = True
292-
for id in sorted(source_id_to_file_names):
293-
if len(id) != 4:
294-
print(f"ID {id} length != 4")
292+
for error_id in sorted(source_id_to_file_names):
293+
if len(error_id) != 4:
294+
print(f"ID {error_id} length != 4")
295295
ok = False
296-
if id[0] == "0":
297-
print(f"ID {id} starts with zero")
296+
if error_id[0] == "0":
297+
print(f"ID {error_id} starts with zero")
298298
ok = False
299-
if len(source_id_to_file_names[id]) > 1:
300-
print(f"ID {id} appears {len(source_id_to_file_names[id])} times")
299+
if len(source_id_to_file_names[error_id]) > 1:
300+
print(f"ID {error_id} appears {len(source_id_to_file_names[error_id])} times")
301301
ok = False
302302

303303
if examine_coverage:
@@ -315,7 +315,7 @@ def main(argv):
315315
if not ok:
316316
print("Incorrect IDs have to be fixed before applying --next")
317317
sys.exit(1)
318-
available_ids = {str(id) for id in range(1000, 10000)} - source_id_to_file_names.keys()
318+
available_ids = {str(error_id) for error_id in range(1000, 10000)} - source_id_to_file_names.keys()
319319
next_id = get_next_id(available_ids)
320320
print(f"Next ID: {next_id}")
321321
sys.exit(0)
@@ -341,7 +341,7 @@ def main(argv):
341341
sys.exit(1)
342342

343343
# number of appearances for every id
344-
source_id_to_count = { id: len(file_names) for id, file_names in source_id_to_file_names.items() }
344+
source_id_to_count = { error_id: len(file_names) for error_id, file_names in source_id_to_file_names.items() }
345345

346346
fix_ids_in_source_files(source_file_names, source_id_to_count)
347347
print("Fixing completed")

scripts/isolate_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def write_cases(f, solidityTests, yulTests):
106106
# When code examples are extracted they are indented by 8 spaces, which violates the style guide,
107107
# so before checking remove 4 spaces from each line.
108108
remainder = dedent(test)
109-
hash = hashlib.sha256(test.encode("utf-8")).hexdigest()
110-
sol_filename = f'test_{hash}_{cleaned_filename}.{language}'
109+
source_code_hash = hashlib.sha256(test.encode("utf-8")).hexdigest()
110+
sol_filename = f'test_{source_code_hash}_{cleaned_filename}.{language}'
111111
with open(sol_filename, mode='w', encoding='utf8', newline='') as fi:
112112
fi.write(remainder)
113113

scripts/pylintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# ATTENTION: This list should be extended with care, consider using NOLINT comments inside your
1515
# python files instead, as the goal is actually to reduce the list of globally disabled checks.
1616
#
17-
# TODO: What could be eliminated in future PRs: bad-continuation, invalid-name, redefined-builtin,
17+
# TODO: What could be eliminated in future PRs: bad-continuation, invalid-name,
1818
# undefined-variable, unused-*, useless-object-inheritance.
1919
disable=
2020
bad-continuation,
@@ -25,7 +25,6 @@ disable=
2525
missing-docstring,
2626
no-else-return,
2727
pointless-string-statement,
28-
redefined-builtin,
2928
redefined-outer-name,
3029
too-few-public-methods,
3130
too-many-public-methods,

scripts/wasm-rebuild/docker-scripts/isolate_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def write_cases(f, tests):
4747
cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower()
4848
for test in tests:
4949
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
50-
hash = hashlib.sha256(test).hexdigest()
51-
with open(f'test_{hash}_{cleaned_filename}.sol', 'w', encoding='utf8') as _f:
50+
source_code_hash = hashlib.sha256(test).hexdigest()
51+
with open(f'test_{source_code_hash}_{cleaned_filename}.sol', 'w', encoding='utf8') as _f:
5252
_f.write(remainder)
5353

5454

0 commit comments

Comments
 (0)