2to3 --fix=idioms
diff --git a/Lib/fontTools/misc/bezierTools.py b/Lib/fontTools/misc/bezierTools.py
index 4c897d5..d15e070 100644
--- a/Lib/fontTools/misc/bezierTools.py
+++ b/Lib/fontTools/misc/bezierTools.py
@@ -132,8 +132,7 @@
a, b, c = calcQuadraticParameters(pt1, pt2, pt3)
solutions = solveQuadratic(a[isHorizontal], b[isHorizontal],
c[isHorizontal] - where)
- solutions = [t for t in solutions if 0 <= t < 1]
- solutions.sort()
+ solutions = sorted([t for t in solutions if 0 <= t < 1])
if not solutions:
return [(pt1, pt2, pt3)]
return _splitQuadraticAtT(a, b, c, *solutions)
@@ -157,8 +156,7 @@
a, b, c, d = calcCubicParameters(pt1, pt2, pt3, pt4)
solutions = solveCubic(a[isHorizontal], b[isHorizontal], c[isHorizontal],
d[isHorizontal] - where)
- solutions = [t for t in solutions if 0 <= t < 1]
- solutions.sort()
+ solutions = sorted([t for t in solutions if 0 <= t < 1])
if not solutions:
return [(pt1, pt2, pt3, pt4)]
return _splitCubicAtT(a, b, c, d, *solutions)
diff --git a/Lib/fontTools/misc/psCharStrings.py b/Lib/fontTools/misc/psCharStrings.py
index f658327..54fdcd0 100644
--- a/Lib/fontTools/misc/psCharStrings.py
+++ b/Lib/fontTools/misc/psCharStrings.py
@@ -65,7 +65,7 @@
def read_realNumber(self, b0, data, index):
number = ''
- while 1:
+ while True:
b = ord(data[index])
index = index + 1
nibble0 = (b & 0xf0) >> 4
@@ -87,7 +87,7 @@
oper[item[0]] = item[1]
else:
oper[item[0]] = item[1:]
- if type(item[0]) == types.TupleType:
+ if isinstance(item[0], types.TupleType):
opc[item[1]] = item[0]
else:
opc[item[1]] = (item[0],)
@@ -334,7 +334,7 @@
return None, 0, 0
token = self.program[index]
index = index + 1
- isOperator = type(token) == StringType
+ isOperator = isinstance(token, StringType)
return token, isOperator, index
def getBytes(self, index, nBytes):
@@ -364,7 +364,7 @@
else:
index = 0
args = []
- while 1:
+ while True:
token, isOperator, index = self.getToken(index)
if token is None:
break
@@ -472,7 +472,7 @@
return
program = []
index = 0
- while 1:
+ while True:
token, isOperator, index = self.getToken(index)
if token is None:
break
@@ -510,7 +510,7 @@
pushToProgram = lambda x: None
pushToStack = self.operandStack.append
index = 0
- while 1:
+ while True:
token, isOperator, index = charString.getToken(index)
if token is None:
break # we're done!
@@ -1143,7 +1143,7 @@
return None, index
def handle_operator(self, operator, argType):
- if type(argType) == type(()):
+ if isinstance(argType, type(())):
value = ()
for i in range(len(argType)-1, -1, -1):
arg = argType[i]
diff --git a/Lib/fontTools/misc/sstruct.py b/Lib/fontTools/misc/sstruct.py
index e2759ef..9363037 100644
--- a/Lib/fontTools/misc/sstruct.py
+++ b/Lib/fontTools/misc/sstruct.py
@@ -63,7 +63,7 @@
def pack(format, object):
formatstring, names, fixes = getformat(format)
elements = []
- if type(object) is not types.DictType:
+ if not isinstance(object, types.DictType):
object = object.__dict__
for name in names:
value = object[name]
@@ -78,7 +78,7 @@
if object is None:
object = {}
formatstring, names, fixes = getformat(format)
- if type(object) is types.DictType:
+ if isinstance(object, types.DictType):
dict = object
else:
dict = object.__dict__
diff --git a/Lib/fontTools/misc/textTools.py b/Lib/fontTools/misc/textTools.py
index fd64ed5..e72282a 100644
--- a/Lib/fontTools/misc/textTools.py
+++ b/Lib/fontTools/misc/textTools.py
@@ -77,8 +77,7 @@
(lower(item), item), alist)
except TypeError:
# at least one element in alist is not a string, proceed the normal way...
- alist = alist[:]
- alist.sort()
+ alist = sorted(alist[:])
return alist
else:
tupledlist.sort()
diff --git a/Lib/fontTools/misc/xmlReader.py b/Lib/fontTools/misc/xmlReader.py
index b2132ef..6dd1e27 100644
--- a/Lib/fontTools/misc/xmlReader.py
+++ b/Lib/fontTools/misc/xmlReader.py
@@ -37,7 +37,7 @@
parser.CharacterDataHandler = self._characterDataHandler
pos = 0
- while 1:
+ while True:
chunk = file.read(BUFSIZE)
if not chunk:
parser.Parse(chunk, 1)
diff --git a/Lib/fontTools/misc/xmlWriter.py b/Lib/fontTools/misc/xmlWriter.py
index 52d9a5c..9246255 100644
--- a/Lib/fontTools/misc/xmlWriter.py
+++ b/Lib/fontTools/misc/xmlWriter.py
@@ -108,8 +108,7 @@
def stringifyattrs(self, *args, **kwargs):
if kwargs:
assert not args
- attributes = kwargs.items()
- attributes.sort()
+ attributes = sorted(kwargs.items())
elif args:
assert len(args) == 1
attributes = args[0]