Skip to content

Commit e8886a4

Browse files
committed
Merge pull request swiftlang#920 from practicalswift/gyb-fixes
[gardening] Clean up .gyb-files: Remove unused imports. Non-controversial PEP8 fixes.
2 parents 755156a + ff0bf80 commit e8886a4

28 files changed

+73
-65
lines changed

lib/Basic/UnicodeExtendedGraphemeClusters.cpp.gyb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
%{
1919

20-
import re
21-
22-
from GYBUnicodeDataUtils import *
20+
from GYBUnicodeDataUtils import GraphemeClusterBreakPropertyTable, get_extended_grapheme_cluster_rules_matrix
2321

2422
grapheme_cluster_break_property_table = \
2523
GraphemeClusterBreakPropertyTable(unicodeGraphemeBreakPropertyFile)

lib/ClangImporter/SortedCFDatabase.def.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ with codecs.open(CFDatabaseFile, encoding='utf-8', errors='strict') as f:
3939
continue
4040

4141
# Otherwise, check for lines like FOO(BAR)
42-
m = re.match('^\w+\((\w+)\)', line)
42+
m = re.match('^\w+\((\w+)\)', line)
4343
if m:
4444
lineForName[m.group(1)] = line
4545
}%

stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types
1616

1717
# Number of bits in the Builtin.Word type
1818
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8

stdlib/public/SDK/CoreGraphics/CoreGraphicsMirrors.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
%TMirrorConformance = gyb.parseTemplate("../../common/MirrorConformance.gyb")
1616
%TMirrorBoilerplate = gyb.parseTemplate("../../common/MirrorBoilerplate.gyb")
1717

18-
% for Type in [['CGPoint',['x','y'],'Point',['x','y']],\
19-
% ['CGSize',['width','height'],'Size',['width','height']],\
18+
% for Type in [['CGPoint',['x','y'],'Point',['x','y']],
19+
% ['CGSize',['width','height'],'Size',['width','height']],
2020
% ['CGRect',['origin','size'],'Rectangle',['origin.x','origin.y','size.width','size.height']]]:
2121
% Self = Type[0]
2222
% Children = Type[1]
@@ -25,11 +25,11 @@
2525
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,introspecteeType=Self,disposition='Struct')
2626
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,introspecteeType=Self,disposition='Struct')
2727
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,introspecteeType=Self,disposition='Struct')
28-
% QLArgFirst=True
28+
% QLArgFirst = True
2929
% QLArgString = ''
3030
% SummaryString = ''
3131
% for QLArg in QLArgs:
32-
% if QLArgFirst == False:
32+
% if not QLArgFirst:
3333
% QLArgString = QLArgString + ', '
3434
% SummaryString = SummaryString + ', '
3535
% else:

stdlib/public/SDK/Foundation/FoundationMirrors.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
// probably not worth trying to write one unique generator - let's
2020
// just use these helpers manually and write the bulk of each one
2121
%{
22-
def getMirrorConformance(Self,Disp = None):
22+
def getMirrorConformance(Self, Disp=None):
2323
return gyb.executeTemplate(
24-
TMirrorConformance,introspecteeType=Self,disposition=Disp)
24+
TMirrorConformance, introspecteeType=Self, disposition=Disp)
2525

26-
def getMirrorBoilerplate(Self,Disp = None):
26+
def getMirrorBoilerplate(Self, Disp=None):
2727
return gyb.executeTemplate(
28-
TMirrorBoilerplate,introspecteeType=Self,disposition=Disp)
28+
TMirrorBoilerplate, introspecteeType=Self, disposition=Disp)
2929

30-
def getMirrorDecl(Self,Disp = None):
31-
return gyb.executeTemplate(TMirrorDecl,introspecteeType=Self,disposition=Disp)
30+
def getMirrorDecl(Self, Disp=None):
31+
return gyb.executeTemplate(TMirrorDecl, introspecteeType=Self, disposition=Disp)
3232
}%
3333

3434
// actual Mirrors

stdlib/public/SDK/simd/simd.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Darwin
3030
// Workaround <rdar://problem/18900352>
3131
% vectype = ctype[type] + str(size)
3232
% llvm_vectype = "Vec" + str(size) + "x" + llvm_type[type]
33-
% vecsize = (8 if type == 'Double' else 4)*(2 if size == 2 else 4)
33+
% vecsize = (8 if type == 'Double' else 4) * (2 if size == 2 else 4)
3434
% extractelement = "extractelement_" + llvm_vectype + "_Int32"
3535
% insertelement = "insertelement_" + llvm_vectype + "_" + llvm_type[type] + "_Int32"
3636
% is_floating = type in floating_types

stdlib/public/common/MirrorBoilerplate.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
# this template, which is probably reasonable since those are "the meat" of every Mirror
2626
}%
2727

28-
%import inspect,os.path,sys
28+
%import inspect
29+
%import os.path
30+
%import sys
2931
%sys.path = [os.path.split(inspect.getframeinfo(inspect.currentframe()).filename)[0] or '.'] + sys.path
3032
%import MirrorCommon
3133
%genericArgString = MirrorCommon.getGenericArgString(

stdlib/public/common/MirrorDecl.gyb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
# this template, which is probably reasonable since those are "the meat" of every Mirror
2626
}%
2727

28-
%import inspect,os.path,sys
28+
%import inspect
29+
%import os.path
30+
%import sys
2931
%sys.path = [os.path.split(inspect.getframeinfo(inspect.currentframe()).filename)[0] or '.'] + sys.path
3032
%import MirrorCommon
31-
%genericConstraintString = MirrorCommon.getGenericConstraintString(\
32-
% genericArgs if 'genericArgs' in locals() else None,\
33-
% genericConstraints if 'genericConstraints' in locals() else None)
33+
%genericConstraintString = MirrorCommon.getGenericConstraintString(
34+
% genericArgs if 'genericArgs' in locals() else None,
35+
% genericConstraints if 'genericConstraints' in locals() else None)
3436

3537
internal struct _${introspecteeType}Mirror${genericConstraintString} : _MirrorType

stdlib/public/core/CollectionMirrors.swift.gyb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
%TMirrorConformance = gyb.parseTemplate("../common/MirrorConformance.gyb")
1616
%TMirrorBoilerplate = gyb.parseTemplate("../common/MirrorBoilerplate.gyb")
1717

18-
% for Type in [['CollectionOfOne',1,"element",\
19-
% 'CollectionOfOne(\( _reflect(_value.element).summary ))'],\
18+
% for Type in [['CollectionOfOne',1,"element",
19+
% 'CollectionOfOne(\( _reflect(_value.element).summary ))'],
2020
% ['EmptyCollection',0,"DONTSHOWME",'EmptyCollection']]:
2121
% Self = Type[0]
2222
% Count = Type[1]
2323
% ElementName = Type[2]
2424
% SummaryString = Type[3]
25-
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,\
26-
% introspecteeType=Self,\
27-
% genericArgs=['T'],\
25+
% MirrorDecl = gyb.executeTemplate(TMirrorDecl,
26+
% introspecteeType=Self,
27+
% genericArgs=['T'],
2828
% disposition='Struct')
29-
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,\
30-
% introspecteeType=Self,\
31-
% genericArgs=['T'],\
29+
% MirrorConformance = gyb.executeTemplate(TMirrorConformance,
30+
% introspecteeType=Self,
31+
% genericArgs=['T'],
3232
% disposition='Struct')
33-
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,\
34-
% introspecteeType=Self,\
35-
% genericArgs=['T'],\
33+
% MirrorBoilerplate = gyb.executeTemplate(TMirrorBoilerplate,
34+
% introspecteeType=Self,
35+
% genericArgs=['T'],
3636
% disposition='Struct')
3737

3838
${MirrorDecl} {

stdlib/public/core/FixedPoint.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init
1616

1717
#
1818
# Utility code for later in this template

stdlib/public/core/FloatingPointOperations.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types
1616

1717
# Number of bits in the Builtin.Word type
1818
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8

stdlib/public/core/IntegerParsing.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types, int_max_bits
1616

1717
# Number of bits in the Builtin.Word type
1818
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8

stdlib/public/core/Interval.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ public func ~= <I: IntervalType>(pattern: I, value: I.Bound) -> Bool {
204204
%import gyb
205205
%TBoilerplate = gyb.parseTemplate("../common/MirrorBoilerplate.gyb")
206206

207-
%Boilerplate = gyb.executeTemplate(TBoilerplate,\
208-
% introspecteeType='T',\
207+
%Boilerplate = gyb.executeTemplate(TBoilerplate,
208+
% introspecteeType='T',
209209
% disposition='Struct')
210210

211211
internal struct _IntervalMirror<

stdlib/public/core/Mirrors.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types
1616

1717
# Number of bits in the Builtin.Word type
1818
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8

stdlib/public/core/Slice.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_slice_doc_comment(Self):
3636
/// the slice may prolong the lifetime of elements that are no longer
3737
/// accessible, which can manifest as apparent memory and object leakage. To
3838
/// prevent this effect, use slices only for transient computation.\
39-
""" % (Self, Self, Self, Self, Self)
39+
""" % (Self, Self, Self, Self, Self)
4040
}%
4141

4242
${get_slice_doc_comment('Slice')}

stdlib/public/core/Sort.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
%{
14-
def cmp(a,b,p):
14+
def cmp(a, b, p):
1515
if p:
16-
return "isOrderedBefore("+a+", "+b+")"
16+
return "isOrderedBefore(" + a + ", " + b + ")"
1717
else:
18-
return "("+a+" < "+b+")"
18+
return "(" + a + " < " + b + ")"
1919

2020
}%
2121

stdlib/public/core/StringInterpolation.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%{
1414

15-
from SwiftIntTypes import *
15+
from SwiftIntTypes import all_integer_types
1616

1717
# Number of bits in the Builtin.Word type
1818
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8

stdlib/public/core/Tuple.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Generate comparison functions for tuples up to some reasonable arity.
1414

1515
% for arity in range(2,7):
16-
% typeParams = [chr(ord("A")+i) for i in range(arity)]
16+
% typeParams = [chr(ord("A") + i) for i in range(arity)]
1717
% tupleT = "({})".format(",".join(typeParams))
1818

1919
% equatableTypeParams = ", ".join(["{} : Equatable".format(c) for c in typeParams])

stdlib/public/stubs/UnicodeExtendedGraphemeClusters.cpp.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# FIXME: this table should be moved to a Swift file in stdlib. Unfortunately,
1616
# in Swift we don't have a way to statically initialize arrays.
1717
18-
from GYBUnicodeDataUtils import *
18+
from GYBUnicodeDataUtils import GraphemeClusterBreakPropertyTable, UnicodeTrieGenerator, get_extended_grapheme_cluster_rules_matrix
1919
2020
grapheme_cluster_break_property_table = \
2121
GraphemeClusterBreakPropertyTable(unicodeGraphemeBreakPropertyFile)

test/1_stdlib/Inputs/flatMap.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
%import inspect,os.path,sys
1+
%import inspect
2+
%import os.path
3+
%import sys
24
%sys.path = [os.path.split(inspect.getframeinfo(inspect.currentframe()).filename)[0] or '.'] + sys.path
35

46
% for Kind in Kinds:

test/1_stdlib/NumericParsing.swift.gyb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@
1616
// RUN: %S/../../utils/line-directive %t/NumericParsing.swift -- %target-run %t/a.out
1717
// REQUIRES: executable_test
1818
%{
19-
from SwiftIntTypes import *
19+
from SwiftIntTypes import all_integer_types
2020

2121
word_bits = int(CMAKE_SIZEOF_VOID_P)
2222

2323
def maskOfWidth(n):
2424
return (1 << n) - 1
2525

26-
def inRadix(radix, n, zero = '0'):
26+
def inRadix(radix, n, zero='0'):
2727
"""
2828
Represent the int n in the given radix.
2929
Note: the third parameter, zero, is not for user consumption.
3030
"""
31-
if n < 0: return '-' + inRadix(radix, -n, '')
32-
elif n == 0: return zero
31+
if n < 0:
32+
return '-' + inRadix(radix, -n, '')
33+
elif n == 0:
34+
return zero
3335
else:
3436
r = n % radix
3537
digit = chr((ord('0') + r) if r < 10 else (ord('a') + r - 10))
@@ -43,7 +45,7 @@ radices_to_test = [2, 8, 10, 16, max_radix]
4345

4446
# How many values to test in each radix? A nice prime number of course.
4547
number_of_values = 23
46-
}%
48+
}%
4749

4850
import StdlibUnittest
4951

test/1_stdlib/Tuple.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ TupleTestSuite.test("Tuple/equality") {
6868

6969
TupleTestSuite.test("Tuple/equality/sanity-check") {
7070
// sanity check all arities
71-
% for arity in range(2,maxArity+1):
71+
% for arity in range(2, maxArity+1):
7272
% a = str(tuple(range(1, arity+1)))
73-
% b = "({}, 0)".format(", ".join([str(i) for i in range(1,arity)]))
74-
% c = "(0, {})".format(", ".join([str(i) for i in range(2,arity+1)]))
73+
% b = "({}, 0)".format(", ".join([str(i) for i in range(1, arity)]))
74+
% c = "(0, {})".format(", ".join([str(i) for i in range(2, arity+1)]))
7575
expectTrue(${a} == ${a})
7676
expectTrue(${a} != ${b})
7777
expectTrue(${b} != ${a})
@@ -147,10 +147,10 @@ TupleTestSuite.test("Tuple/comparison") {
147147

148148
TupleTestSuite.test("Tuple/comparison/sanity-check") {
149149
// sanity check all arities
150-
% for arity in range(2,maxArity+1):
150+
% for arity in range(2, maxArity+1):
151151
% a = str(tuple(range(1, arity+1)))
152-
% b = "({}, 0)".format(", ".join([str(i) for i in range(1,arity)]))
153-
% c = "(0, {})".format(", ".join([str(i) for i in range(2,arity+1)]))
152+
% b = "({}, 0)".format(", ".join([str(i) for i in range(1, arity)]))
153+
% c = "(0, {})".format(", ".join([str(i) for i in range(2, arity+1)]))
154154
expectTrue(${b} < ${a})
155155
expectTrue(${b} <= ${a})
156156
expectTrue(${a} > ${c})

unittests/Basic/UnicodeGraphemeBreakTest.cpp.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
%{
1919

20-
from GYBUnicodeDataUtils import *
20+
from GYBUnicodeDataUtils import get_grapheme_cluster_break_tests_as_UTF8
2121

2222
grapheme_cluster_break_tests = \
2323
get_grapheme_cluster_break_tests_as_UTF8(unicodeGraphemeBreakTestFile)

validation-test/stdlib/FixedPoint.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_fixed_point_hash(bit_pattern, src_bits, word_bits):
7878

7979
truncating_bit_pattern_test_template = gyb.parseTemplate("truncating_bit_pattern",
8080
"""
81-
% from SwiftIntTypes import *
81+
% from SwiftIntTypes import all_integer_types, should_define_truncating_bit_pattern_init
8282

8383
% for dst_ty in all_integer_types(word_bits):
8484
% Dst = dst_ty.stdlib_name
@@ -149,7 +149,7 @@ _UnimplementedError()
149149

150150
bit_pattern_test_template = gyb.parseTemplate("bit_pattern",
151151
"""
152-
% from SwiftIntTypes import *
152+
% from SwiftIntTypes import all_integer_types
153153

154154
% for dst_ty in all_integer_types(word_bits):
155155
% Dst = dst_ty.stdlib_name
@@ -225,7 +225,7 @@ _UnimplementedError()
225225

226226
hash_value_test_template = gyb.parseTemplate("hash_value",
227227
"""
228-
% from SwiftIntTypes import *
228+
% from SwiftIntTypes import all_integer_types
229229

230230
% for self_ty in all_integer_types(word_bits):
231231
% Self = self_ty.stdlib_name

validation-test/stdlib/FixedPointArithmeticTraps.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func expectNoOverflow<T>(
5050

5151
%{
5252

53-
from SwiftIntTypes import *
53+
from SwiftIntTypes import all_integer_types
5454

5555
# Test cases are written in a way that they don't depend on the word size.
5656
word_bits = 4

validation-test/stdlib/FloatingPointConversionTraps.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ObjectiveC
2020

2121
%{
2222

23-
from SwiftIntTypes import *
23+
from SwiftIntTypes import all_integer_types
2424

2525
# Test cases are written in a way that they don't depend on the word size.
2626
word_bits = 4

validation-test/stdlib/NumericDiagnostics.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// TODO: Verify the type of the result
1616

1717
func testIteratedOperations() {
18-
% for typesToTest, operatorsToTest in zip([all_integer_type_names(), all_numeric_type_names()], \
18+
% for typesToTest, operatorsToTest in zip([all_integer_type_names(), all_numeric_type_names()],
1919
% [int_ops, arith_ops]):
2020
% operatorsToTest = [x for x in operatorsToTest if not '+' in x and not '-' in x]
2121
%# TODO: rm when rdar://18695154 is fixed.

validation-test/stdlib/Slice/Inputs/slice.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
%import inspect,os.path,sys
1+
%import inspect
2+
%import os.path
3+
%import sys
24
%sys.path = [os.path.split(inspect.getframeinfo(inspect.currentframe()).filename)[0] or '.'] + sys.path
35

46
% Base = "%s%s%sCollection" % (base_kind, traversal, 'Mutable' if mutable else '')

0 commit comments

Comments
 (0)