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
8 changes: 8 additions & 0 deletions src/future/types/newstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __repr__(self):
"""
Without the u prefix
"""

value = super(newstr, self).__repr__()
# assert value[0] == u'u'
return value[1:]
Expand Down Expand Up @@ -292,6 +293,13 @@ def __eq__(self, other):
else:
return False

def __hash__(self):
if (isinstance(self, unicode) or
isinstance(self, bytes) and not isnewbytes(self)):
return super(newstr, self).__hash__()
else:
raise NotImplementedError()

def __ne__(self, other):
if (isinstance(other, unicode) or
isinstance(other, bytes) and not isnewbytes(other)):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_future/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ def test_eq(self):
self.assertFalse(b'ABCD' == s)
self.assertFalse(bytes(b'ABCD') == s)

def test_hash(self):
s = str('ABCD')
self.assertIsInstance(hash(s),int)

def test_ne(self):
s = str('ABCD')
self.assertNotEqual('A', s)
Expand Down