Skip to content

Commit

Permalink
Merge pull request #734 from googlefonts/minor-cleanup
Browse files Browse the repository at this point in the history
Use isinstance checks
  • Loading branch information
anthrotype authored Oct 25, 2021
2 parents 352b8dd + 5a7f7a2 commit e00221c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions Lib/glyphsLib/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ def parse_hint_target(line=None):
return line


def isString(string):
return isinstance(string, str)


def transformStructToScaleAndRotation(transform):
Det = transform[0] * transform[3] - transform[1] * transform[2]
_sX = math.sqrt(math.pow(transform[0], 2) + math.pow(transform[1], 2))
Expand Down Expand Up @@ -486,29 +482,26 @@ class FontFontMasterProxy(Proxy):
"""

def __getitem__(self, Key):
if type(Key) == slice:
if isinstance(Key, str):
# UUIDs are case-sensitive in Glyphs.app.
return next((master for master in self.values() if master.id == Key), None)
if isinstance(Key, slice):
return self.values().__getitem__(Key)
if type(Key) is int:
if isinstance(Key, int):
if Key < 0:
Key = self.__len__() + Key
return self.values()[Key]
elif isString(Key):
# UUIDs are case-sensitive in Glyphs.app.
for master in self.values():
if master.id == Key:
return master
else:
raise KeyError
raise KeyError(Key)

def __setitem__(self, Key, FontMaster):
FontMaster.font = self._owner
if type(Key) is int:
if isinstance(Key, int):
OldFontMaster = self.__getitem__(Key)
if Key < 0:
Key = self.__len__() + Key
FontMaster.id = OldFontMaster.id
self._owner._masters[Key] = FontMaster
elif isString(Key):
elif isinstance(Key, str):
OldFontMaster = self.__getitem__(Key)
FontMaster.id = OldFontMaster.id
Index = self._owner._masters.index(OldFontMaster)
Expand All @@ -517,7 +510,7 @@ def __setitem__(self, Key, FontMaster):
raise KeyError

def __delitem__(self, Key):
if type(Key) is int:
if isinstance(Key, int):
if Key < 0:
Key = self.__len__() + Key
return self.remove(self._owner._masters[Key])
Expand Down Expand Up @@ -595,7 +588,7 @@ def __getitem__(self, key):
return None

def __setitem__(self, key, glyph):
if type(key) is int:
if isinstance(key, int):
self._owner._setupGlyph(glyph)
self._owner._glyphs[key] = glyph
else:
Expand All @@ -604,7 +597,7 @@ def __setitem__(self, key, glyph):
def __delitem__(self, key):
if isinstance(key, int):
del self._owner._glyphs[key]
elif isString(key):
elif isinstance(key, str):
glyph = self._get_glyph_by_string(key)
if not glyph:
raise KeyError("No glyph '%s' in the font" % key)
Expand All @@ -613,7 +606,7 @@ def __delitem__(self, key):
raise KeyError

def __contains__(self, item):
if isString(item):
if isinstance(item, str):
return self._get_glyph_by_string(item) is not None
return item in self._owner._glyphs

Expand Down Expand Up @@ -757,7 +750,7 @@ def __getitem__(self, key):
if self._owner.parent:
return list(self)[key]
return list(self.values())[key]
elif isString(key):
elif isinstance(key, str):
if key in self._owner._layers:
return self._owner._layers[key]

Expand Down Expand Up @@ -1094,7 +1087,7 @@ def __delitem__(self, key):
raise KeyError

def __contains__(self, item):
if isString(item):
if isinstance(item, str):
if item == "Axes" and isinstance(self._owner, GSFont):
return self._owner.axes
if item == "Axis Location" and isinstance(self._owner, GSInstance):
Expand Down Expand Up @@ -1125,7 +1118,7 @@ def extend(self, parameters):
self._owner._customParameters.extend(parameters)

def remove(self, parameter):
if isString(parameter):
if isinstance(parameter, str):
parameter = self.__getitem__(parameter)
self._owner._customParameters.remove(parameter)

Expand Down

0 comments on commit e00221c

Please sign in to comment.