File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ def __repr__(self):
105105 """
106106 Without the u prefix
107107 """
108+
108109 value = super (newstr , self ).__repr__ ()
109110 # assert value[0] == u'u'
110111 return value [1 :]
@@ -292,6 +293,13 @@ def __eq__(self, other):
292293 else :
293294 return False
294295
296+ def __hash__ (self ):
297+ if (isinstance (self , unicode ) or
298+ isinstance (self , bytes ) and not isnewbytes (self )):
299+ return super (newstr , self ).__hash__ ()
300+ else :
301+ raise NotImplementedError ()
302+
295303 def __ne__ (self , other ):
296304 if (isinstance (other , unicode ) or
297305 isinstance (other , bytes ) and not isnewbytes (other )):
Original file line number Diff line number Diff line change @@ -363,6 +363,10 @@ def test_eq(self):
363363 self .assertFalse (b'ABCD' == s )
364364 self .assertFalse (bytes (b'ABCD' ) == s )
365365
366+ def test_hash (self ):
367+ s = str ('ABCD' )
368+ self .assertIsInstance (hash (s ),int )
369+
366370 def test_ne (self ):
367371 s = str ('ABCD' )
368372 self .assertNotEqual ('A' , s )
You can’t perform that action at this time.
0 commit comments