Skip to content

Commit

Permalink
Improve handling of None sort keys
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness committed Oct 10, 2019
1 parent af9c505 commit 480ee7d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions source/mutable.py
Expand Up @@ -373,7 +373,9 @@ def sortkey(self, testcase, sortkey=None):
try:
cached_sortkey = self._sortkey_lookup[testcase.id]
if sortkey is None: # no need to change value
return cached_sortkey
# In Python 3 we cannot compare None to int
# so it's better to return 0 instead of None
return cached_sortkey or 0
except AttributeError: # cache doesn't exist yet
self._sortkey_lookup = {}
except KeyError: # not yet in cache
Expand All @@ -395,11 +397,9 @@ def sortkey(self, testcase, sortkey=None):
# Cache sortkey for future
self._sortkey_lookup[testcase.id] = caseplan.sortkey
# And finally return the current value
if caseplan.sortkey is None:
# None and int is not comparable in Python 3
return 0
else:
return caseplan.sortkey
# In Python 3 we cannot compare None to int
# so it's better to return 0 instead of None
return caseplan.sortkey or 0

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TestRun Class
Expand Down

0 comments on commit 480ee7d

Please sign in to comment.