Skip to content

Commit 1edb62d

Browse files
[Python] Make flake8 linting pass without errors/warning (w/ default rules)
1 parent ee3e7a5 commit 1edb62d

24 files changed

+104
-89
lines changed

.pep8

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[flake8]
22
filename = *.py,Benchmark_Driver,Benchmark_DTrace.in,Benchmark_GuardMalloc.in,Benchmark_RuntimeLeaksRunner.in,build-script,gyb,line-directive,ns-html2rst,recursive-lipo,rth,submit-benchmark-results,update-checkout,viewcfg
3-
max-line-length = 80

benchmark/scripts/Benchmark_DTrace.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- Benchmark_DTrace.in ----------------------------------------------===//
3+
# ===--- Benchmark_DTrace.in ---------------------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
import argparse
1616
import os

benchmark/scripts/Benchmark_Driver

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
# ===--- Benchmark_Driver -------------------------------------------------===//
4+
# ===--- Benchmark_Driver ------------------------------------------------===//
55
#
66
# This source file is part of the Swift.org open source project
77
#
@@ -11,7 +11,7 @@
1111
# See http://swift.org/LICENSE.txt for license information
1212
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1313
#
14-
# ===----------------------------------------------------------------------===//
14+
# ===---------------------------------------------------------------------===//
1515

1616
import argparse
1717
import datetime
@@ -109,10 +109,10 @@ def instrument_test(driver_path, test, num_samples):
109109
avg_test_output[i] = int(round(avg_test_output[i] /
110110
float(len(test_outputs))))
111111
avg_test_output[num_samples_index] = num_samples
112-
avg_test_output[min_index] = min(test_outputs,
113-
key=lambda x: int(x[min_index]))[min_index]
114-
avg_test_output[max_index] = max(test_outputs,
115-
key=lambda x: int(x[max_index]))[max_index]
112+
avg_test_output[min_index] = min(
113+
test_outputs, key=lambda x: int(x[min_index]))[min_index]
114+
avg_test_output[max_index] = max(
115+
test_outputs, key=lambda x: int(x[max_index]))[max_index]
116116
avg_test_output = map(str, avg_test_output)
117117

118118
return avg_test_output

benchmark/scripts/Benchmark_GuardMalloc.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- Benchmark_GuardMalloc.in -----------------------------------------===//
3+
# ===--- Benchmark_GuardMalloc.in ----------------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
import os
1616
import subprocess

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- Benchmark_RuntimeLeaksRunner.in ----------------------------------===//
3+
# ===--- Benchmark_RuntimeLeaksRunner.in ---------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
import json
1616
import os
@@ -26,8 +26,8 @@ import perf_test_driver # noqa (E402 module level import not at top of file)
2626
XFAIL_LIST = [
2727
]
2828

29-
# Global objective-c classes created by various frameworks. We do not care about
30-
# these.
29+
# Global objective-c classes created by various frameworks. We do not care
30+
# about these.
3131
IGNORABLE_GLOBAL_OBJC_CLASSES = set([
3232
'__NSPlaceholderDate',
3333
'NSCache',

benchmark/scripts/compare_perf_tests.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33

4-
# ===--- compare_perf_tests.py --------------------------------------------===//
4+
# ===--- compare_perf_tests.py -------------------------------------------===//
55
#
66
# This source file is part of the Swift.org open source project
77
#
@@ -11,7 +11,7 @@
1111
# See http://swift.org/LICENSE.txt for license information
1212
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1313
#
14-
# ===----------------------------------------------------------------------===//
14+
# ===---------------------------------------------------------------------===//
1515

1616
# e.g.
1717
# repeat.sh 3 tot/bin/Benchmark_Driver run -o -O > tot.O.times
@@ -136,7 +136,8 @@ def compare_scores(key, score1, worstsample1, score2, worstsample2, runs, num):
136136

137137
if bestscore1 != 0 and bestscore2 != 0:
138138
print(("%+.1f%%" %
139-
(((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9), end="")
139+
(((float(bestscore2) / bestscore1) - 1) * 100)).rjust(9),
140+
end="")
140141
if ShowSpeedup:
141142
Num, Den = float(bestscore2), float(bestscore1)
142143
if IsTime:

benchmark/scripts/generate_harness/generate_harness.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- generate_harness.py ----------------------------------------------===//
3+
# ===--- generate_harness.py ---------------------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
# Generate CMakeLists.txt and utils/main.swift from templates.
1616

benchmark/scripts/perf_test_driver/perf_test_driver.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- perf_test_driver.py ----------------------------------------------===//
3+
# ===--- perf_test_driver.py ---------------------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
import multiprocessing
1616
import os

benchmark/utils/convertToJSON.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# ===--- convertToJSON.py -------------------------------------------------===//
3+
# ===--- convertToJSON.py ------------------------------------------------===//
44
#
55
# This source file is part of the Swift.org open source project
66
#
@@ -10,7 +10,7 @@
1010
# See http://swift.org/LICENSE.txt for license information
1111
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1212
#
13-
# ===----------------------------------------------------------------------===//
13+
# ===---------------------------------------------------------------------===//
1414

1515
# This script converts results from pre-commit benchmark tests to JSON.
1616
# Usage: PrecommitBench_O | convertToJSON.py

docs/conf.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# Swift documentation build configuration file.
44
#
5-
# This file is execfile()d with the current directory set to its containing dir.
5+
# This file is execfile()d with the current directory set to its containing
6+
# dir.
67
#
78
# Note that not all possible configuration values are present in this
89
# autogenerated file.
@@ -23,8 +24,8 @@
2324
# If your documentation needs a minimal Sphinx version, state it here.
2425
# needs_sphinx = '1.0'
2526

26-
# Add any Sphinx extension module names here, as strings. They can be extensions
27-
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
27+
# Add any Sphinx extension module names here, as strings. They can be
28+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2829
extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo']
2930

3031
# Add any paths that contain templates here, relative to this directory.
@@ -66,7 +67,8 @@
6667
# directories to ignore when looking for source files.
6768
exclude_patterns = ['_build']
6869

69-
# The reST default role (used for this markup: `text`) to use for all documents.
70+
# The reST default role (used for this markup: `text`) to use for all
71+
# documents.
7072
# default_role = None
7173

7274
# If true, '()' will be appended to :func: etc. cross-reference text.
@@ -190,7 +192,8 @@
190192
}
191193

192194
# Grouping the document tree into LaTeX files. List of tuples
193-
# (source start file, target name, title, author, documentclass [howto/manual]).
195+
# (source start file, target name, title, author, documentclass
196+
# [howto/manual]).
194197
latex_documents = [
195198
('contents', 'Swift.tex', u'Swift Documentation',
196199
u'LLVM project', 'manual'),

utils/GYBUnicodeDataUtils.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ===--- GYBUnicodeDataUtils.py -----------------------*- coding: utf-8 -*-===//
1+
# ===--- GYBUnicodeDataUtils.py ----------------------*- coding: utf-8 -*-===//
22
#
33
# This source file is part of the Swift.org open source project
44
#
@@ -105,8 +105,8 @@ def __init__(self, grapheme_break_property_file_name):
105105
for cp in range(0, 0x110000):
106106
self.property_values[cp] = self.get_default_value()
107107

108-
for start_code_point, end_code_point, val in self.property_value_ranges:
109-
for cp in range(start_code_point, end_code_point + 1):
108+
for start_code_pt, end_code_pt, val in self.property_value_ranges:
109+
for cp in range(start_code_pt, end_code_pt + 1):
110110
self.property_values[cp] = val
111111

112112
def get_default_value(self):
@@ -320,7 +320,8 @@ def get_value(self, cp):
320320
if cp <= 0xffff:
321321
data_block_index = self.bmp_lookup[
322322
self.get_bmp_first_level_index(cp)]
323-
return self.bmp_data[data_block_index][self.get_bmp_data_offset(cp)]
323+
return self.bmp_data[data_block_index][
324+
self.get_bmp_data_offset(cp)]
324325
else:
325326
second_lookup_index = self.supp_lookup1[
326327
self.get_supp_first_level_index(cp)]
@@ -552,14 +553,14 @@ def _convert_line(line):
552553
pass
553554
else:
554555
code_point = int(token, 16)
555-
# Tests from Unicode spec have isolated surrogates in them. Our
556-
# segmentation algorithm works on UTF-8 sequences, so encoding a
557-
# surrogate would produce an invalid code unit sequence.
558-
# Instead of trying to emulate the maximal subpart algorithm for
559-
# inserting U+FFFD in Python, we just replace every isolated
560-
# surrogate with U+200B, which also has Grapheme_Cluster_Break
561-
# equal to 'Control' and test separately that we handle
562-
# ill-formed UTF-8 sequences.
556+
# Tests from Unicode spec have isolated surrogates in them.
557+
# Our segmentation algorithm works on UTF-8 sequences, so
558+
# encoding a surrogate would produce an invalid code unit
559+
# sequence. Instead of trying to emulate the maximal subpart
560+
# algorithm for inserting U+FFFD in Python, we just replace
561+
# every isolated surrogate with U+200B, which also has
562+
# Grapheme_Cluster_Break equal to 'Control' and test
563+
# separately that we handle ill-formed UTF-8 sequences.
563564
if code_point >= 0xd800 and code_point <= 0xdfff:
564565
code_point = 0x200b
565566
code_point = (b'\U%(cp)08x' % {b'cp': code_point}).decode(
@@ -613,14 +614,14 @@ def _convert_line(line):
613614
pass
614615
else:
615616
code_point = int(token, 16)
616-
# Tests from Unicode spec have isolated surrogates in them. Our
617+
# Tests from Unicode spec have isolated surrogates in them. Our
617618
# segmentation algorithm works on UTF-16 sequences, so encoding
618619
# a surrogate would produce an invalid code unit sequence.
619-
# Instead of trying to emulate the maximal subpart algorithm for
620-
# inserting U+FFFD in Python, we just replace every isolated
621-
# surrogate with U+200B, which also has Grapheme_Cluster_Break
622-
# equal to 'Control' and test separately that we handle
623-
# ill-formed UTF-8 sequences.
620+
# Instead of trying to emulate the maximal subpart algorithm
621+
# for inserting U+FFFD in Python, we just replace every
622+
# isolated surrogate with U+200B, which also has
623+
# Grapheme_Cluster_Break equal to 'Control' and test separately
624+
# that we handle ill-formed UTF-8 sequences.
624625
if code_point >= 0xd800 and code_point <= 0xdfff:
625626
code_point = 0x200b
626627
test += [code_point]

utils/SwiftIntTypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ===--- SwiftIntTypes.py -----------------------------*- coding: utf-8 -*-===//
1+
# ===--- SwiftIntTypes.py ----------------------------*- coding: utf-8 -*-===//
22
#
33
# This source file is part of the Swift.org open source project
44
#

utils/build-script

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ To use it, specify the '--preset=' argument:
284284
285285
[~/src/s]$ ./swift/utils/build-script --preset=ds
286286
./swift/utils/build-script: using preset 'ds', which expands to
287-
./swift/utils/build-script --release --debug-swift --debug-swift-stdlib --test
287+
./swift/utils/build-script --release --debug-swift --debug-swift-stdlib \
288+
--test
288289
--build-subdir=ds --
289290
...
290291

utils/cmpcodesize/cmpcodesize/compare.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ====--- compare.py - Compare built products' sizes --*- coding: utf-8 -*-===//
1+
# ====--- compare.py - Compare built products' sizes -*- coding: utf-8 -*-===//
22
#
33
# This source file is part of the Swift.org open source project
44
#

utils/cmpcodesize/cmpcodesize/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def main():
3838
3939
Environment variables:
4040
SWIFT_NEW_BUILDDIR The new build-dir
41-
E.g. $HOME/swiftnew/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
41+
E.g. .../swiftnew/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
4242
SWIFT_OLD_BUILDDIR The old build-dir
43-
E.g. $HOME/swiftold/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
43+
E.g. .../swiftold/build/Ninja-ReleaseAssert+stdlib-Release/swift-macosx-x86_64
4444
4545
How to specify files:
4646
1) No files:

utils/gyb.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ def code_starts_with_dedent_keyword(source_lines):
360360
False
361361
>>> code_starts_with_dedent_keyword(split_lines('except ifSomethingElse:'))
362362
True
363-
>>> code_starts_with_dedent_keyword(split_lines('\n# comment\nelse: # yes'))
363+
>>> code_starts_with_dedent_keyword(
364+
split_lines('\n# comment\nelse: # yes'))
364365
True
365366
"""
366367
token_text = None
@@ -449,7 +450,7 @@ def token_generator(self, base_tokens):
449450
... '''% for x in [1, 2, 3]:
450451
... % if x == 1:
451452
... literal1
452-
... % elif x > 1: # add an output line after this line to fix the bug
453+
... % elif x > 1: # add an output line after this line to fix bug
453454
... % if x == 2:
454455
... literal2
455456
... % end
@@ -544,7 +545,8 @@ def next_token(self):
544545
class ExecutionContext(object):
545546
"""State we pass around during execution of a template"""
546547

547-
def __init__(self, line_directive='// ###sourceLocation', **local_bindings):
548+
def __init__(self, line_directive='// ###sourceLocation',
549+
**local_bindings):
548550
self.local_bindings = local_bindings
549551
self.line_directive = line_directive
550552
self.local_bindings['__context__'] = self
@@ -753,7 +755,7 @@ def parse_template(filename, text=None):
753755
{
754756
if x == 1:
755757
__children__[0].execute(__context__)
756-
elif x > 1: # add output line after this line to fix the bug
758+
elif x > 1: # add output line after this line to fix bug
757759
__children__[1].execute(__context__)
758760
}
759761
[

0 commit comments

Comments
 (0)