Lift .get("hex") out of try:; and avoid re-evaluating it

This commit is contained in:
David Jones 2024-07-18 19:29:41 +01:00
parent 7d39064a36
commit aa2d9196c0

View File

@ -1191,12 +1191,12 @@ def _readGlyphFromTreeFormat1(
haveSeenAdvance = True haveSeenAdvance = True
_readAdvance(glyphObject, element) _readAdvance(glyphObject, element)
elif element.tag == "unicode": elif element.tag == "unicode":
if element.get("hex") is None: v = element.get("hex")
if v is None:
raise GlifLibError( raise GlifLibError(
"A unicode element is missing its required hex attribute." "A unicode element is missing its required hex attribute."
) )
try: try:
v = element.get("hex")
v = int(v, 16) v = int(v, 16)
if v not in unicodes: if v not in unicodes:
unicodes.append(v) unicodes.append(v)
@ -1258,12 +1258,12 @@ def _readGlyphFromTreeFormat2(
haveSeenAdvance = True haveSeenAdvance = True
_readAdvance(glyphObject, element) _readAdvance(glyphObject, element)
elif element.tag == "unicode": elif element.tag == "unicode":
if element.get("hex") is None: v = element.get("hex")
if v is None:
raise GlifLibError( raise GlifLibError(
"A unicode element is missing its required hex attribute." "A unicode element is missing its required hex attribute."
) )
try: try:
v = element.get("hex")
v = int(v, 16) v = int(v, 16)
if v not in unicodes: if v not in unicodes:
unicodes.append(v) unicodes.append(v)