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
2 changes: 1 addition & 1 deletion src/future/types/newstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __eq__(self, other):
isinstance(other, bytes) and not isnewbytes(other)):
return super(newstr, self).__eq__(other)
else:
return False
return NotImplemented

def __hash__(self):
if (isinstance(self, unicode) or
Expand Down
10 changes: 8 additions & 2 deletions tests/test_future/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,24 @@ def test_eq(self):
self.assertFalse(b'ABCD' == s)
self.assertFalse(bytes(b'ABCD') == s)

# We want to ensure comparison against unknown types return
# NotImplemented so that the interpreter can rerun the test with the
# other class. We expect the operator to return False if both return
# NotImplemented.
class OurCustomString(object):
def __init__(self, string):
self.string = string

def __str__(self):
return self.string
def __eq__(self, other):
return NotImplemented

our_str = OurCustomString("foobar")
new_str = str("foobar")

self.assertFalse(our_str == new_str)
self.assertFalse(new_str == our_str)
self.assertIs(new_str.__eq__(our_str), NotImplemented)
self.assertIs(our_str.__eq__(new_str), NotImplemented)

def test_hash(self):
s = str('ABCD')
Expand Down