diff --git a/rattail/gpc.py b/rattail/gpc.py index b6da852e352b58f7fe19f475e3fa1a6184ee1c05..748cefda35d9d3ee0e1831bd4fc51c8da844e856 100644 --- a/rattail/gpc.py +++ b/rattail/gpc.py @@ -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)