Skip to content

Commit 6a219f8

Browse files
committed
klass comparison hopefully improved
1 parent ed694b3 commit 6a219f8

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

MiddleKit/Core/Klass.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,17 +366,15 @@ def __str__(self):
366366
def __hash__(self):
367367
return hash(self.name()) # | hash(self.model().name())
368368

369-
def __cmp__(self, other):
370-
if other is None:
371-
return 1
372-
if not isinstance(other, Klass):
373-
return 1
374-
if self.model() is not other.model():
375-
value = cmp(self.model().name(), other.model().name())
376-
if value == 0:
377-
value = cmp(self.name(), other.name())
378-
return value
379-
return cmp(self.name(), other.name())
369+
def __eq__(self, other):
370+
if other is None or not isinstance(other, Klass):
371+
return False
372+
#if self.model() is not other.model():
373+
# value = cmp(self.model().name(), other.model().name())
374+
# if value == 0:
375+
# value = cmp(self.name(), other.name())
376+
# return value
377+
return self.name() == other.name()
380378

381379

382380
## Warnings ##

MiddleKit/Run/ObjectKey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def serialNum(self):
4141
# return result
4242
def __eq__(self, other ):
4343
return self._className == other._className and self._serialNum == other._serialNum
44-
44+
#according to http://python3porting.com/preparing.html hash will then be set to None automatically
4545
def __hash__(self):
4646
return hash(self._className) ^ hash(self._serialNum)
4747

MiddleKit/Tests/MKBackRef.mkmodel/TestSamples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ def test(store):
55
for n in nodes:
66
children = n.children()
77
if children:
8-
children.sort(key=lambda c: c.serialNum)
8+
sorted(children, key=lambda c: c.serialNum() )
99
assert n.value() == ''.join([c.value() for c in children])

MiddleKit/Tests/Test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def readArgs(self, args):
7979
MKBasic MKNone MKString MKDateTime MKEnums MKDefaultMinMax
8080
MKTypeValueChecking MKInheritance MKInheritanceAbstract
8181
MKList MKObjRef MKObjRefReuse MKDelete MKDeleteMark
82+
MKBackRef MKClone MKDump MKRefresh
8283
MKMultipleStores MKMultipleThreads
8384
MKModelInh1 MKModelInh2 MKModelInh3
8485
MKExcel

0 commit comments

Comments
 (0)