Changeset - 5d3b002ebfef
[Not reviewed]
0 1 0
Lance Edgar - 9 years ago 2016-03-11 15:05:02
ledgar@sacfoodcoop.com
Fix `cmp(GPC)` behavior when `other` is None etc.
1 file changed with 14 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rattail/gpc.py
Show inline comments
 
@@ -2,7 +2,7 @@
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2014 Lance Edgar
 
#  Copyright © 2010-2016 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
@@ -24,7 +24,7 @@
 
Global Product Code
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 
from rattail import barcodes
 

	
 
@@ -74,13 +74,20 @@ class GPC(object):
 
            return True
 

	
 
    def __cmp__(self, other):
 
        if int(self) < int(other):
 

	
 
        # treat non-integers as being less than myself
 
        try:
 
            other = int(other)
 
        except (TypeError, ValueError):
 
            return 1
 

	
 
        myself = int(self)
 
        if myself < other:
 
            return -1
 
        if int(self) > int(other):
 
        if myself > other:
 
            return 1
 
        if int(self) == int(other):
 
            return 0
 
        assert False
 
        assert myself == other
 
        return 0
 

	
 
    def __hash__(self):
 
        return hash(self.value)
0 comments (0 inline, 0 general)