-
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 fixes - fix base folder #6252
Changes from all commits
fe67aea
94895ec
347d4ea
19f4a47
8b03f85
9e1683e
a28cdcf
7fa7e6d
57ba4d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,18 @@ def components(self): | |
def _is_valid_operand(self, other): | ||
return hasattr(other, '_components') | ||
|
||
def _fill_value_if_missing(self, ours, theirs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python 2 allows comparing ints and strs, but Py3 doesn't. So, the old fillvalue of
|
||
if theirs is None: | ||
return ours, type(ours)() # gets type's zero-value, e.g. 0 or "" | ||
elif ours is None: | ||
return type(theirs)(), theirs | ||
return ours, theirs | ||
|
||
def _stringify_if_different_types(self, ours, theirs): | ||
if any(isinstance(v, str) for v in (ours, theirs)): | ||
return str(ours), str(theirs) | ||
return ours, theirs | ||
|
||
def __repr__(self): | ||
return '{}({})'.format(self.__class__.__name__, ', '.join(map(repr, self._components))) | ||
|
||
|
@@ -106,8 +118,10 @@ def __lt__(self, other): | |
if not self._is_valid_operand(other): | ||
return AttributeError # TODO(python3port): typically this should return NotImplemented. | ||
# Returning AttributeError for now to avoid changing prior API. | ||
for ours, theirs in zip_longest(self._components, other._components, fillvalue=0): | ||
for ours, theirs in zip_longest(self._components, other._components, fillvalue=None): | ||
if ours != theirs: | ||
ours, theirs = self._fill_value_if_missing(ours, theirs) | ||
ours, theirs = self._stringify_if_different_types(ours, theirs) | ||
return ours < theirs | ||
return False | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hasher requires byte strings. Most of the changes made below are converting to bytes.