Skip to content

Commit 1dbed8a

Browse files
authored
Merge pull request #11599 from ethereum/fix-pylint
Fix pylint issues in CI
2 parents eaac16c + 0ef7d27 commit 1dbed8a

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

scripts/endToEndExtraction/verify-testcases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def diff(self, analyser):
155155
print(len(intersection), "test-cases - ", len(mismatches), " mismatche(s)")
156156

157157
def check_traces(self, test_name, left, right, mismatches):
158-
for trace_id in range(0, len(left.traces)):
159-
left_trace = left.traces[trace_id]
158+
for trace_id, trace in enumerate(left.traces):
159+
left_trace = trace
160160
right_trace = right.traces[trace_id]
161161
assert (left_trace.kind == right_trace.kind)
162162
if str(left_trace) != str(right_trace):

scripts/extract_test_cases.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import re
1111

1212
def extract_test_cases(_path):
13-
lines = open(_path, mode='rb', encoding='utf8').read().splitlines()
13+
with open(_path, mode='rb', encoding='utf8') as f:
14+
lines = f.read().splitlines()
1415

1516
inside = False
1617
delimiter = ''
@@ -22,7 +23,8 @@ def extract_test_cases(_path):
2223
for l in lines:
2324
if inside:
2425
if l.strip().endswith(')' + delimiter + '";'):
25-
open('%03d_%s.sol' % (ctr, test_name), mode='wb', encoding='utf8').write(test)
26+
with open('%03d_%s.sol' % (ctr, test_name), mode='wb', encoding='utf8') as f:
27+
f.write(test)
2628
ctr += 1
2729
inside = False
2830
test = ''

scripts/isolate_tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from os.path import join, isfile, split
1414

1515
def extract_test_cases(path):
16-
lines = open(path, encoding="utf8", errors='ignore', mode='r', newline='').read().splitlines()
16+
with open(path, encoding="utf8", errors='ignore', mode='r', newline='') as file:
17+
lines = file.read().splitlines()
1718

1819
inside = False
1920
delimiter = ''
@@ -45,7 +46,10 @@ def extract_docs_cases(path):
4546
tests = []
4647

4748
# Collect all snippets of indented blocks
48-
for l in open(path, mode='r', errors='ignore', encoding='utf8', newline='').read().splitlines():
49+
50+
with open(path, mode='r', errors='ignore', encoding='utf8', newline='') as f:
51+
lines = f.read().splitlines()
52+
for l in lines:
4953
if l != '':
5054
if not insideBlock and l.startswith(' '):
5155
# start new test
@@ -87,14 +91,16 @@ def write_cases(f, tests):
8791
# so before checking remove 4 spaces from each line.
8892
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
8993
sol_filename = 'test_%s_%s.sol' % (hashlib.sha256(test.encode("utf-8")).hexdigest(), cleaned_filename)
90-
open(sol_filename, mode='w', encoding='utf8', newline='').write(remainder)
94+
with open(sol_filename, mode='w', encoding='utf8', newline='') as fi:
95+
fi.write(remainder)
9196

9297
def extract_and_write(f, path):
9398
if docs:
9499
cases = extract_docs_cases(path)
95100
else:
96101
if f.endswith('.sol'):
97-
cases = [open(path, mode='r', encoding='utf8', newline='').read()]
102+
with open(path, mode='r', encoding='utf8', newline='') as _f:
103+
cases = [_f.read()]
98104
else:
99105
cases = extract_test_cases(path)
100106
write_cases(f, cases)

scripts/regressions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def process_log(self, logfile):
8888

8989
## Log may contain non ASCII characters, so we simply stringify them
9090
## since they don't matter for regular expression matching
91-
rawtext = str(open(logfile, 'rb').read())
91+
with open(logfile, 'rb') as f:
92+
rawtext = str(f.read())
9293
return not re.search(self._re_sanitizer_log, rawtext)
9394

9495
def run(self):

scripts/splitSources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def writeSourceToFile(lines):
6363

6464
try:
6565
# decide if file has multiple sources
66-
lines = open(filePath, mode='r', encoding='utf8', newline='').read().splitlines()
66+
with open(filePath, mode='r', encoding='utf8', newline='') as f:
67+
lines = f.read().splitlines()
6768
if lines[0][:12] == "==== Source:":
6869
hasMultipleSources = True
6970
writeSourceToFile(lines)

scripts/update_bugs_by_version.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def comp(version_string):
2626
versions[m.group(1)] = {}
2727
versions[m.group(1)]['released'] = m.group(2)
2828

29-
for v in versions:
30-
versions[v]['bugs'] = []
29+
for key, value in versions.items():
30+
value['bugs'] = []
3131
for bug in bugs:
32-
if 'introduced' in bug and comp(bug['introduced']) > comp(v):
32+
if 'introduced' in bug and comp(bug['introduced']) > comp(key):
3333
continue
34-
if comp(bug['fixed']) <= comp(v):
34+
if comp(bug['fixed']) <= comp(key):
3535
continue
36-
versions[v]['bugs'] += [bug['name']]
36+
value['bugs'] += [bug['name']]
3737

3838
new_contents = json.dumps(versions, sort_keys=True, indent=4, separators=(',', ': '))
3939
with open(path + '/../docs/bugs_by_version.json', 'r') as bugs_by_version:

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99

1010
def extract_test_cases(path):
11-
lines = open(path, encoding="utf8", errors='ignore', mode='rb').read().splitlines()
11+
with open(path, encoding="utf8", errors='ignore', mode='rb') as f:
12+
lines = f.read().splitlines()
1213

1314
inside = False
1415
delimiter = ''
@@ -32,7 +33,8 @@ def extract_test_cases(path):
3233

3334
def extract_and_write(f, path):
3435
if f.endswith('.sol'):
35-
cases = [open(path, 'r').read()]
36+
with open(path, 'r') as _f:
37+
cases = [_f.read()]
3638
else:
3739
cases = extract_test_cases(path)
3840
write_cases(f, cases)
@@ -41,7 +43,8 @@ def write_cases(f, tests):
4143
cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower()
4244
for test in tests:
4345
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
44-
open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'w').write(remainder)
46+
with open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'w') as _f:
47+
_f.write(remainder)
4548

4649

4750
if __name__ == '__main__':

0 commit comments

Comments
 (0)