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):
105
105
"""
106
106
Without the u prefix
107
107
"""
108
+
108
109
value = super (newstr , self ).__repr__ ()
109
110
# assert value[0] == u'u'
110
111
return value [1 :]
@@ -292,6 +293,13 @@ def __eq__(self, other):
292
293
else :
293
294
return False
294
295
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
+
295
303
def __ne__ (self , other ):
296
304
if (isinstance (other , unicode ) or
297
305
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):
363
363
self .assertFalse (b'ABCD' == s )
364
364
self .assertFalse (bytes (b'ABCD' ) == s )
365
365
366
+ def test_hash (self ):
367
+ s = str ('ABCD' )
368
+ self .assertIsInstance (hash (s ),int )
369
+
366
370
def test_ne (self ):
367
371
s = str ('ABCD' )
368
372
self .assertNotEqual ('A' , s )
You can’t perform that action at this time.
0 commit comments