Make __cmp__() functions stable
diff --git a/Lib/fontTools/ttLib/tables/DefaultTable.py b/Lib/fontTools/ttLib/tables/DefaultTable.py
index ff45bc3..8d68ec0 100644
--- a/Lib/fontTools/ttLib/tables/DefaultTable.py
+++ b/Lib/fontTools/ttLib/tables/DefaultTable.py
@@ -37,9 +37,8 @@
return "<'%s' table at %x>" % (self.tableTag, id(self))
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
diff --git a/Lib/fontTools/ttLib/tables/M_E_T_A_.py b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
index 492ed60..b8fb640 100644
--- a/Lib/fontTools/ttLib/tables/M_E_T_A_.py
+++ b/Lib/fontTools/ttLib/tables/M_E_T_A_.py
@@ -238,9 +238,8 @@
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.glyphID, other.glyphID)
@@ -328,9 +327,8 @@
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.labelID, other.labelID)
diff --git a/Lib/fontTools/ttLib/tables/_c_m_a_p.py b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
index b33d951..ecc5668 100644
--- a/Lib/fontTools/ttLib/tables/_c_m_a_p.py
+++ b/Lib/fontTools/ttLib/tables/_c_m_a_p.py
@@ -151,9 +151,8 @@
writer.newline()
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
# implemented so that list.sort() sorts according to the cmap spec.
selfTuple = (
diff --git a/Lib/fontTools/ttLib/tables/_g_l_y_f.py b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
index 418d450..6a370c1 100644
--- a/Lib/fontTools/ttLib/tables/_g_l_y_f.py
+++ b/Lib/fontTools/ttLib/tables/_g_l_y_f.py
@@ -721,9 +721,8 @@
self.data = data
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
@@ -885,9 +884,8 @@
self.flags = safeEval(attrs["flags"])
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
diff --git a/Lib/fontTools/ttLib/tables/_h_e_a_d.py b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
index 060930f..61d9a16 100644
--- a/Lib/fontTools/ttLib/tables/_h_e_a_d.py
+++ b/Lib/fontTools/ttLib/tables/_h_e_a_d.py
@@ -90,9 +90,8 @@
setattr(self, name, value)
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
selfdict = self.__dict__.copy()
otherdict = other.__dict__.copy()
diff --git a/Lib/fontTools/ttLib/tables/_k_e_r_n.py b/Lib/fontTools/ttLib/tables/_k_e_r_n.py
index 005d1ed..22c5552 100644
--- a/Lib/fontTools/ttLib/tables/_k_e_r_n.py
+++ b/Lib/fontTools/ttLib/tables/_k_e_r_n.py
@@ -164,9 +164,8 @@
del self.kernTable[pair]
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
diff --git a/Lib/fontTools/ttLib/tables/_l_o_c_a.py b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
index 87b047d..21c31ad 100644
--- a/Lib/fontTools/ttLib/tables/_l_o_c_a.py
+++ b/Lib/fontTools/ttLib/tables/_l_o_c_a.py
@@ -60,9 +60,8 @@
return len(self.locations)
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.locations, other.locations)
diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
index 307fbb5..2270983 100644
--- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py
+++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py
@@ -89,9 +89,8 @@
return None # not found
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.names, other.names)
@@ -139,9 +138,8 @@
"""Compare method, so a list of NameRecords can be sorted
according to the spec by just sorting it..."""
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
selftuple = (self.platformID,
self.platEncID,
diff --git a/Lib/fontTools/ttLib/tables/otBase.py b/Lib/fontTools/ttLib/tables/otBase.py
index 0f6a4e8..8eec6b0 100644
--- a/Lib/fontTools/ttLib/tables/otBase.py
+++ b/Lib/fontTools/ttLib/tables/otBase.py
@@ -288,9 +288,8 @@
return hash(self.items)
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.items, other.items)
@@ -671,9 +670,8 @@
setattr(self, conv.name, value)
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)
@@ -835,8 +833,7 @@
setattr(self, name, value)
def __cmp__(self, other):
- if type(self) != type(other) or \
- self.__class__ != other.__class__:
- return cmp(id(self), id(other))
+ if type(self) != type(other): return cmp(type(self), type(other))
+ if self.__class__ != other.__class__: return cmp(self.__class__, other.__class__)
return cmp(self.__dict__, other.__dict__)