Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/future/types/newbytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,24 +348,24 @@ def __ne__(self, other):
unorderable_err = 'unorderable types: bytes() and {0}'

def __lt__(self, other):
if not isbytes(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newbytes, self).__lt__(other)
if isinstance(other, _builtin_bytes):
return super(newbytes, self).__lt__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __le__(self, other):
if not isbytes(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newbytes, self).__le__(other)
if isinstance(other, _builtin_bytes):
return super(newbytes, self).__le__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __gt__(self, other):
if not isbytes(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newbytes, self).__gt__(other)
if isinstance(other, _builtin_bytes):
return super(newbytes, self).__gt__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __ge__(self, other):
if not isbytes(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newbytes, self).__ge__(other)
if isinstance(other, _builtin_bytes):
return super(newbytes, self).__ge__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __native__(self):
# We can't just feed a newbytes object into str(), because
Expand Down
28 changes: 16 additions & 12 deletions src/future/types/newstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,24 +302,28 @@ def __ne__(self, other):
unorderable_err = 'unorderable types: str() and {0}'

def __lt__(self, other):
if not istext(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newstr, self).__lt__(other)
if (isinstance(other, unicode) or
isinstance(other, bytes) and not isnewbytes(other)):
return super(newstr, self).__lt__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __le__(self, other):
if not istext(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newstr, self).__le__(other)
if (isinstance(other, unicode) or
isinstance(other, bytes) and not isnewbytes(other)):
return super(newstr, self).__le__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __gt__(self, other):
if not istext(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newstr, self).__gt__(other)
if (isinstance(other, unicode) or
isinstance(other, bytes) and not isnewbytes(other)):
return super(newstr, self).__gt__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __ge__(self, other):
if not istext(other):
raise TypeError(self.unorderable_err.format(type(other)))
return super(newstr, self).__ge__(other)
if (isinstance(other, unicode) or
isinstance(other, bytes) and not isnewbytes(other)):
return super(newstr, self).__ge__(other)
raise TypeError(self.unorderable_err.format(type(other)))

def __getattribute__(self, name):
"""
Expand Down
4 changes: 0 additions & 4 deletions tests/test_future/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ def test_cmp(self):
s > 3
with self.assertRaises(TypeError):
s < 1000
with self.assertRaises(TypeError):
s > b'XYZ'
with self.assertRaises(TypeError):
s < b'XYZ'
with self.assertRaises(TypeError):
s <= 3
with self.assertRaises(TypeError):
Expand Down