Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code formatting and some comparisons #3449

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions Lib/fontTools/cu2qu/cu2qu.py
Expand Up @@ -487,16 +487,16 @@ def curves_to_quadratic(curves, max_errors, all_quadratic=True):

Example::

>>> curves_to_quadratic( [
... [ (50,50), (100,100), (150,100), (200,50) ],
... [ (75,50), (120,100), (150,75), (200,60) ]
... ], [1,1] )
>>> curves_to_quadratic([
... [(50,50), (100,100), (150,100), (200,50)],
... [(75,50), (120,100), (150,75), (200,60)]
...], [1,1])
[[(50.0, 50.0), (75.0, 75.0), (125.0, 91.66666666666666), (175.0, 75.0), (200.0, 50.0)], [(75.0, 50.0), (97.5, 75.0), (135.41666666666666, 82.08333333333333), (175.0, 67.5), (200.0, 60.0)]]

The returned splines have "implied oncurve points" suitable for use in
TrueType ``glif`` outlines - i.e. in the first spline returned above,
the first quadratic segment runs from (50,50) to
( (75 + 125)/2 , (120 + 91.666..)/2 ) = (100, 83.333...).
((75 + 125) / 2 , (120 + 91.666..) / 2) = (100, 83.333...).

Returns:
If all_quadratic is True, a list of splines, each spline being a list
Expand Down
10 changes: 5 additions & 5 deletions Lib/fontTools/designspaceLib/__init__.py
Expand Up @@ -1539,7 +1539,7 @@ def _makeLocationElement(self, locationObject, name=None):
for dimensionName, dimensionValue in validatedLocation.items():
dimElement = ET.Element("dimension")
dimElement.attrib["name"] = dimensionName
if type(dimensionValue) == tuple:
if isinstance(dimensionValue, tuple):
dimElement.attrib["xvalue"] = self.intOrFloat(dimensionValue[0])
dimElement.attrib["yvalue"] = self.intOrFloat(dimensionValue[1])
else:
Expand Down Expand Up @@ -2813,8 +2813,8 @@ def updatePaths(self):
::

case 1.
descriptor.filename == None
descriptor.path == None
descriptor.filename is None
descriptor.path is None

-- action:
write as is, descriptors will not have a filename attr.
Expand All @@ -2823,14 +2823,14 @@ def updatePaths(self):

case 2.
descriptor.filename == "../something"
descriptor.path == None
descriptor.path is None

-- action:
write as is. The filename attr should not be touched.


case 3.
descriptor.filename == None
descriptor.filename is None
descriptor.path == "~/absolute/path/there"

-- action:
Expand Down
8 changes: 4 additions & 4 deletions Lib/fontTools/feaLib/ast.py
Expand Up @@ -563,12 +563,12 @@ class MarkClassDefinition(Statement):
.. code:: python

mc = MarkClass("FRENCH_ACCENTS")
mc.addDefinition( MarkClassDefinition(mc, Anchor(350, 800),
mc.addDefinition(MarkClassDefinition(mc, Anchor(350, 800),
GlyphClass([ GlyphName("acute"), GlyphName("grave") ])
) )
mc.addDefinition( MarkClassDefinition(mc, Anchor(350, -200),
))
mc.addDefinition(MarkClassDefinition(mc, Anchor(350, -200),
GlyphClass([ GlyphName("cedilla") ])
) )
))

mc.asFea()
# markClass [acute grave] <anchor 350 800> @FRENCH_ACCENTS;
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/merge/base.py
Expand Up @@ -39,7 +39,7 @@ def mergeObjects(lst):
return None

clazz = lst[0].__class__
assert all(type(item) == clazz for item in lst), lst
assert all(isinstance(item, clazz) for item in lst), lst

logic = clazz.mergeMap
returnTable = clazz()
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontTools/misc/bezierTools.py
Expand Up @@ -867,7 +867,7 @@ def solveCubic(a, b, c, d):
[0.5, 0.5, 0.5]
>>> solveCubic(
... 9.0, 0.0, 0.0, -7.62939453125e-05
... ) == [-0.0, -0.0, -0.0]
...) == [-0.0, -0.0, -0.0]
True
"""
#
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def lineLineIntersections(s1, e1, s2, e2):

Examples::

>>> a = lineLineIntersections( (310,389), (453, 222), (289, 251), (447, 367))
>>> a = lineLineIntersections((310,389), (453, 222), (289, 251), (447, 367))
>>> len(a)
1
>>> intersection = a[0]
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/misc/configTools.py
Expand Up @@ -198,7 +198,7 @@ class AbstractConfig(MutableMapping):
class MyConfig(AbstractConfig):
options = Options()

MyConfig.register_option( "test:option_name", "This is an option", 0, int, lambda v: isinstance(v, int))
MyConfig.register_option("test:option_name", "This is an option", 0, int, lambda v: isinstance(v, int))

cfg = MyConfig({"test:option_name": 10})

Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/misc/psOperators.py
Expand Up @@ -512,7 +512,7 @@ def ps_for(self):
else:
if i < limit:
break
if type(i) == type(0.0):
if isinstance(i, float):
self.push(ps_real(i))
else:
self.push(ps_integer(i))
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/misc/vector.py
Expand Up @@ -23,7 +23,7 @@ def __new__(cls, values, keep=False):
"the 'keep' argument has been deprecated",
DeprecationWarning,
)
if type(values) == Vector:
if isinstance(values, Vector):
# No need to create a new object
return values
return super().__new__(cls, values)
Expand Down
10 changes: 5 additions & 5 deletions Lib/fontTools/misc/visitor.py
Expand Up @@ -15,9 +15,9 @@ def _register(celf, clazzes_attrs):
def wrapper(method):
assert method.__name__ == "visit"
for clazzes, attrs in clazzes_attrs:
if type(clazzes) != tuple:
if not isinstance(clazzes, tuple):
clazzes = (clazzes,)
if type(attrs) == str:
if isinstance(attrs, str):
attrs = (attrs,)
for clazz in clazzes:
_visitors = celf._visitors.setdefault(clazz, {})
Expand All @@ -33,16 +33,16 @@ def wrapper(method):

@classmethod
def register(celf, clazzes):
if type(clazzes) != tuple:
if not isinstance(clazzes, tuple):
clazzes = (clazzes,)
return celf._register([(clazzes, (None,))])

@classmethod
def register_attr(celf, clazzes, attrs):
clazzes_attrs = []
if type(clazzes) != tuple:
if not isinstance(clazzes, tuple):
clazzes = (clazzes,)
if type(attrs) == str:
if isinstance(attrs, str):
attrs = (attrs,)
for clazz in clazzes:
clazzes_attrs.append((clazz, attrs))
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/mtiLib/__init__.py
Expand Up @@ -1283,7 +1283,7 @@ def between(self, tag):

@contextmanager
def until(self, tags):
if type(tags) is not tuple:
if not isinstance(tags, tuple):
tags = (tags,)
self.stoppers.extend(tags)
yield
Expand Down
16 changes: 8 additions & 8 deletions Lib/fontTools/otlLib/builder.py
Expand Up @@ -698,7 +698,7 @@ class ChainContextPosBuilder(ChainContextualBuilder):
suffix = [ ["E"] ]
glyphs = [ ["x"], ["y"], ["z"] ]
lookups = [ [lu1], None, [lu2] ]
builder.rules.append( (prefix, glyphs, suffix, lookups) )
builder.rules.append((prefix, glyphs, suffix, lookups))

Attributes:
font (``fontTools.TTLib.TTFont``): A font object.
Expand Down Expand Up @@ -743,7 +743,7 @@ class ChainContextSubstBuilder(ChainContextualBuilder):
suffix = [ ["E"] ]
glyphs = [ ["x"], ["y"], ["z"] ]
lookups = [ [lu1], None, [lu2] ]
builder.rules.append( (prefix, glyphs, suffix, lookups) )
builder.rules.append((prefix, glyphs, suffix, lookups))

Attributes:
font (``fontTools.TTLib.TTFont``): A font object.
Expand Down Expand Up @@ -1155,7 +1155,7 @@ class ReverseChainSingleSubstBuilder(LookupBuilder):
prefix = [ ["a", "e", "n"] ]
suffix = []
mapping = { "d": "d.alt" }
builder.substitutions.append( (prefix, suffix, mapping) )
builder.substitutions.append((prefix, suffix, mapping))

Attributes:
font (``fontTools.TTLib.TTFont``): A font object.
Expand Down Expand Up @@ -2092,7 +2092,7 @@ def buildPairPosClassesSubtable(pairs, glyphMap, valueFormat1=None, valueFormat2
pairs[(
[ "K", "X" ],
[ "W", "V" ]
)] = ( buildValue(xAdvance=+5), buildValue() )
)] = (buildValue(xAdvance=+5), buildValue())
# pairs[(... , ...)] = (..., ...)

pairpos = buildPairPosClassesSubtable(pairs, font.getReverseGlyphMap())
Expand Down Expand Up @@ -2163,8 +2163,8 @@ def buildPairPosGlyphs(pairs, glyphMap):
Example::

pairs = {
("K", "W"): ( buildValue(xAdvance=+5), buildValue() ),
("K", "V"): ( buildValue(xAdvance=+5), buildValue() ),
("K", "W"): (buildValue(xAdvance=+5), buildValue()),
("K", "V"): (buildValue(xAdvance=+5), buildValue()),
# ...
}

Expand Down Expand Up @@ -2206,8 +2206,8 @@ def buildPairPosGlyphsSubtable(pairs, glyphMap, valueFormat1=None, valueFormat2=
Example::

pairs = {
("K", "W"): ( buildValue(xAdvance=+5), buildValue() ),
("K", "V"): ( buildValue(xAdvance=+5), buildValue() ),
("K", "W"): (buildValue(xAdvance=+5), buildValue()),
("K", "V"): (buildValue(xAdvance=+5), buildValue()),
# ...
}

Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/pens/statisticsPen.py
Expand Up @@ -34,7 +34,7 @@ def _update(self):
self.stddevX = stddevX = sqrt(self.varianceX)
self.stddevY = stddevY = sqrt(self.varianceY)

# Correlation(X,Y) = Covariance(X,Y) / ( stddev(X) * stddev(Y) )
# Correlation(X,Y) = Covariance(X,Y) / (stddev(X) * stddev(Y))
# https://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient
if stddevX * stddevY == 0:
correlation = float("NaN")
Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/ttLib/tables/DefaultTable.py
Expand Up @@ -40,7 +40,7 @@ def __repr__(self):
return "<'%s' table at %x>" % (self.tableTag, id(self))

def __eq__(self, other):
if type(self) != type(other):
if type(self) is not type(other):
return NotImplemented
return self.__dict__ == other.__dict__

Expand Down
2 changes: 1 addition & 1 deletion Lib/fontTools/ttLib/tables/G__l_a_t.py
Expand Up @@ -17,7 +17,7 @@
Glat_format_3 = """
>
version: 16.16F
compression:L # compression scheme or reserved
compression:L # compression scheme or reserved
"""

Glat_format_1_entry = """
Expand Down
4 changes: 2 additions & 2 deletions Lib/fontTools/ttLib/tables/TupleVariation.py
Expand Up @@ -86,11 +86,11 @@ def toXML(self, writer, axisTags):
writer.newline()
wrote_any_deltas = False
for i, delta in enumerate(self.coordinates):
if type(delta) == tuple and len(delta) == 2:
if isinstance(delta, tuple) and len(delta) == 2:
writer.simpletag("delta", pt=i, x=delta[0], y=delta[1])
writer.newline()
wrote_any_deltas = True
elif type(delta) == int:
elif isinstance(delta, int):
writer.simpletag("delta", cvt=i, value=delta)
writer.newline()
wrote_any_deltas = True
Expand Down
26 changes: 11 additions & 15 deletions Lib/fontTools/ttLib/tables/_g_l_y_f.py
Expand Up @@ -6,8 +6,7 @@
from fontTools import version
from fontTools.misc.transform import DecomposedTransform
from fontTools.misc.textTools import tostr, safeEval, pad
from fontTools.misc.arrayTools import updateBounds, pointInRect
from fontTools.misc.bezierTools import calcQuadraticBounds
from fontTools.misc.arrayTools import updateBounds
from fontTools.misc.fixedTools import (
fixedToFloat as fi2fl,
floatToFixed as fl2fi,
Expand All @@ -23,7 +22,6 @@
import struct
import array
import logging
import math
import os
from fontTools.misc import xmlWriter
from fontTools.misc.filenames import userNameToFileName
Expand Down Expand Up @@ -196,7 +194,6 @@ def toXML(self, writer, ttFont, splitGlyphs=False):
writer.comment(notice)
writer.newline()
writer.newline()
numGlyphs = len(glyphNames)
if splitGlyphs:
path, ext = os.path.splitext(writer.file.name)
existingGlyphFiles = set()
Expand Down Expand Up @@ -574,12 +571,12 @@ def setCoordinates(self, glyphName, ttFont):


glyphHeaderFormat = """
> # big endian
numberOfContours: h
xMin: h
yMin: h
xMax: h
yMax: h
> # big endian
numberOfContours: h
xMin: h
yMin: h
xMax: h
yMax: h
"""

# flags
Expand Down Expand Up @@ -1106,7 +1103,6 @@ def compileDeltasOptimal(self, flags, deltas):
candidates = []
bestTuple = None
bestCost = 0
repeat = 0
for flag, (x, y) in zip(flags, deltas):
# Oh, the horrors of TrueType
flag, coordBytes = flagBest(x, y, flag)
Expand Down Expand Up @@ -1607,7 +1603,7 @@ def drawPoints(self, pen, glyfTable, offset=0):
pen.endPath()

def __eq__(self, other):
if type(self) != type(other):
if type(self) is not type(other):
return NotImplemented
return self.__dict__ == other.__dict__

Expand Down Expand Up @@ -1933,7 +1929,7 @@ def fromXML(self, name, attrs, content, ttFont):
self.flags = safeEval(attrs["flags"])

def __eq__(self, other):
if type(self) != type(other):
if type(self) is not type(other):
return NotImplemented
return self.__dict__ == other.__dict__

Expand Down Expand Up @@ -2318,7 +2314,7 @@ def setCoordinates(self, coords):
return coords[i:]

def __eq__(self, other):
if type(self) != type(other):
if type(self) is not type(other):
return NotImplemented
return self.__dict__ == other.__dict__

Expand Down Expand Up @@ -2489,7 +2485,7 @@ def __eq__(self, other):
>>> g2 == g3
False
"""
if type(self) != type(other):
if type(self) is not type(other):
return NotImplemented
return self._a == other._a

Expand Down