From: Stefan Behnel Date: Fri, 21 Aug 2009 06:41:53 +0000 (+0200) Subject: __cmp__() is dead in Py3, ep+lt should be enough though X-Git-Tag: 0.12.alpha0~247 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8371e5da99b245bdb442df057acb89d64d1b3bda;p=cython.git __cmp__() is dead in Py3, ep+lt should be enough though --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 6a18d19a..e49b067d 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -736,12 +736,20 @@ class CComplexType(CNumericType): self.binops = {} self.from_parts = "%s_from_parts" % self.specalization_name() - def __cmp__(self, other): + def __eq__(self, other): if isinstance(self, CComplexType) and isinstance(other, CComplexType): - return cmp(self.real_type, other.real_type) + return self.real_type == other.real_type else: - return 1 - + return False + + def __lt__(self, other): + if isinstance(self, CComplexType) and isinstance(other, CComplexType): + return self.real_type < other.real_type + else: + # this is arbitrary, but it makes sure we always have + # *some* kind of order + return False + def __hash__(self): return ~hash(self.real_type) @@ -1348,14 +1356,19 @@ class CStructOrUnionType(CType): base = "%s %s" % (self.kind, self.cname) return self.base_declaration_code(public_decl(base, dll_linkage), entity_code) - def __cmp__(self, other): + def __eq__(self, other): try: - if self.name == other.name: - return 0 - else: - return 1 + return self.name == other.name except AttributeError: - return 1 + return False + + def __lt__(self, other): + try: + return self.name < other.name + except AttributeError: + # this is arbitrary, but it makes sure we always have + # *some* kind of order + return False def is_complete(self): return self.scope is not None