Compare enums by identity

This commit is contained in:
Simon Cozens 2021-03-17 14:59:11 +00:00
parent b26728d3cb
commit bfc4ac9524

View File

@ -50,7 +50,7 @@ class VarLibMergeError(VarLibError):
if "expected" in cause and "got" in cause: if "expected" in cause and "got" in cause:
index = [x == cause["expected"] for x in cause["got"]].index(False) index = [x == cause["expected"] for x in cause["got"]].index(False)
return index, self._master_name(index) return index, self._master_name(index)
if reason == VarLibMergeFailure.FoundANone: if reason is VarLibMergeFailure.FoundANone:
index = [x is None for x in cause["got"]].index(True) index = [x is None for x in cause["got"]].index(True)
return index, self._master_name(index) return index, self._master_name(index)
return None, None return None, None
@ -80,10 +80,10 @@ class VarLibMergeError(VarLibError):
offender_index, offender = self._offender(cause) offender_index, offender = self._offender(cause)
if offender: if offender:
details = f"\n\nThe problem is likely to be in {offender}:\n" details = f"\n\nThe problem is likely to be in {offender}:\n"
if cause["reason"] == VarLibMergeFailure.FoundANone: if cause["reason"] is VarLibMergeFailure.FoundANone:
details = details + f"{stack[0]}=={cause['got']}\n" details = details + f"{stack[0]}=={cause['got']}\n"
elif ( elif (
cause["reason"] == VarLibMergeFailure.ShouldBeConstant cause["reason"] is VarLibMergeFailure.ShouldBeConstant
and stack[0] == ".FeatureCount" and stack[0] == ".FeatureCount"
): ):
# Common case # Common case
@ -96,8 +96,8 @@ class VarLibMergeError(VarLibError):
) )
if ( if (
cause["reason"] == VarLibMergeFailure.UnsupportedFormat cause["reason"] is VarLibMergeFailure.UnsupportedFormat
or cause["reason"] == VarLibMergeFailure.InconsistentFormat or cause["reason"] is VarLibMergeFailure.InconsistentFormat
): ):
reason = reason % cause["subtable"] reason = reason % cause["subtable"]
basic = textwrap.fill( basic = textwrap.fill(