Skip to content

Commit 0769e4d

Browse files
authored
Merge pull request #12445 from ethereum/pylint-enable-more-warnings
[pylint] Enable more warnings
2 parents 4149560 + 589f4b2 commit 0769e4d

File tree

12 files changed

+81
-84
lines changed

12 files changed

+81
-84
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
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
@@ -73,7 +73,7 @@ def setup(sphinx):
7373
with open('../CMakeLists.txt', 'r', encoding='utf8') as f:
7474
version = re.search('PROJECT_VERSION "([^"]+)"', f.read()).group(1)
7575
# The full version, including alpha/beta/rc tags.
76-
if os.path.isfile('../prerelease.txt') != True or os.path.getsize('../prerelease.txt') == 0:
76+
if not os.path.isfile('../prerelease.txt') or os.path.getsize('../prerelease.txt') == 0:
7777
release = version
7878
else:
7979
# This is a prerelease version

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: 20 additions & 19 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:
@@ -154,7 +154,8 @@ def diff(self, analyser):
154154

155155
print(len(intersection), "test-cases - ", len(mismatches), " mismatche(s)")
156156

157-
def check_traces(self, test_name, left, right, mismatches):
157+
@classmethod
158+
def check_traces(cls, test_name, left, right, mismatches):
158159
for trace_id, trace in enumerate(left.traces):
159160
left_trace = trace
160161
right_trace = right.traces[trace_id]

scripts/error_codes.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def read_file(file_name):
1818
with open(file_name, "r", encoding="latin-1" if is_latin else ENCODING) as f:
1919
content = f.read()
2020
finally:
21-
if content == None:
21+
if content is None:
2222
print(f"Error reading: {file_name}")
2323
return content
2424

@@ -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

@@ -277,7 +277,7 @@ def main(argv):
277277

278278
if [check, fix, examine_coverage, next_id].count(True) != 1:
279279
print("usage: python error_codes.py --check | --fix [--no-confirm] | --examine-coverage | --next")
280-
exit(1)
280+
sys.exit(1)
281281

282282
cwd = os.getcwd()
283283

@@ -289,23 +289,23 @@ 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:
304304
if not ok:
305305
print("Incorrect IDs have to be fixed before applying --examine-coverage")
306-
exit(1)
306+
sys.exit(1)
307307
res = 0 if examine_id_coverage(cwd, source_id_to_file_names) else 1
308-
exit(res)
308+
sys.exit(res)
309309

310310
ok &= examine_id_coverage(cwd, source_id_to_file_names, new_ids_only=True)
311311

@@ -314,18 +314,18 @@ def main(argv):
314314
if next_id:
315315
if not ok:
316316
print("Incorrect IDs have to be fixed before applying --next")
317-
exit(1)
318-
available_ids = {str(id) for id in range(1000, 10000)} - source_id_to_file_names.keys()
317+
sys.exit(1)
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}")
321-
exit(0)
321+
sys.exit(0)
322322

323323
if ok:
324324
print("No incorrect IDs found")
325-
exit(0)
325+
sys.exit(0)
326326

327327
if check:
328-
exit(1)
328+
sys.exit(1)
329329

330330
assert fix, "Unexpected state, should not come here without --fix"
331331

@@ -338,14 +338,14 @@ def main(argv):
338338
while len(answer) == 0 or answer not in "YNyn":
339339
answer = input("[Y/N]? ")
340340
if answer not in "yY":
341-
exit(1)
341+
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")
348-
exit(2)
348+
sys.exit(2)
349349

350350

351351
if __name__ == "__main__":

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/pylint_all.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
from argparse import ArgumentParser
88
from os import path, walk
9-
from sys import exit
109
from textwrap import dedent
1110
import subprocess
11+
import sys
1212

1313
PROJECT_ROOT = path.dirname(path.dirname(path.realpath(__file__)))
1414
PYLINT_RCFILE = f"{PROJECT_ROOT}/scripts/pylintrc"
@@ -89,7 +89,7 @@ def main():
8989
success = pylint_all_filenames(options.dev_mode, rootdirs)
9090

9191
if not success:
92-
exit(1)
92+
sys.exit(1)
9393
else:
9494
print("No problems found.")
9595

@@ -98,4 +98,4 @@ def main():
9898
try:
9999
main()
100100
except KeyboardInterrupt:
101-
exit("Interrupted by user. Exiting.")
101+
sys.exit("Interrupted by user. Exiting.")

scripts/pylintrc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,18 @@
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,
18-
# undefined-variable, unused-*, useless-object-inheritance.
17+
# TODO: What could be eliminated in future PRs: invalid-name, pointless-string-statement, redefined-outer-name.
1918
disable=
20-
bad-continuation,
2119
bad-indentation,
2220
bad-whitespace,
23-
consider-using-sys-exit,
2421
duplicate-code,
2522
invalid-name,
2623
missing-docstring,
2724
no-else-return,
28-
no-self-use,
2925
pointless-string-statement,
30-
redefined-builtin,
3126
redefined-outer-name,
32-
singleton-comparison,
3327
too-few-public-methods,
34-
too-many-public-methods,
35-
ungrouped-imports
28+
too-many-public-methods
3629

3730
[BASIC]
3831

scripts/regressions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def __init__(self, description, args):
4141
"build/test/tools/ossfuzz")
4242
self._logpath = os.path.join(self._repo_root, "test_results")
4343

44-
def parseCmdLine(self, description, args):
44+
@classmethod
45+
def parseCmdLine(cls, description, args):
4546
argParser = ArgumentParser(description)
4647
argParser.add_argument('-o', '--out-dir', required=True, type=str,
4748
help="""Directory where test results will be written""")

scripts/splitSources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def writeSourceToFile(lines):
4040
filePath, srcName = extractSourceName(lines[0])
4141
# print("sourceName is ", srcName)
4242
# print("filePath is", filePath)
43-
if filePath != False:
43+
if filePath:
4444
os.system("mkdir -p " + filePath)
4545
with open(srcName, mode='a+', encoding='utf8', newline='') as f:
4646
createdSources.append(srcName)

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)