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