Author: Tyler Wade <[email protected]>
Branch: utf8-unicode2
Changeset: r72722:a97578376264
Date: 2014-08-08 22:42 -0500
http://bitbucket.org/pypy/pypy/changeset/a97578376264/
Log: Fix unicode keys in (app-level) dictionaries
diff --git a/pypy/interpreter/utf8.py b/pypy/interpreter/utf8.py
--- a/pypy/interpreter/utf8.py
+++ b/pypy/interpreter/utf8.py
@@ -1,6 +1,6 @@
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.objectmodel import (
- we_are_translated, specialize, import_from_mixin)
+ we_are_translated, specialize, import_from_mixin, compute_hash)
from rpython.rlib.runicode import utf8_code_length
from rpython.rlib.unicodedata import unicodedb_5_2_0 as unicodedb
from rpython.rlib.rarithmetic import r_uint, intmask, base_int
@@ -230,7 +230,7 @@
return self._len
def __hash__(self):
- return hash(self.bytes)
+ return compute_hash(self.bytes)
def __eq__(self, other):
if isinstance(other, Utf8Str):
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -9,6 +9,7 @@
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import (
WrappedDefault, applevel, interp2app, unwrap_spec)
+from pypy.interpreter.utf8 import Utf8Str
from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter.signature import Signature
from pypy.objspace.std.stdtypedef import StdTypeDef
@@ -1035,7 +1036,6 @@
create_iterator_classes(BytesDictStrategy)
-
class UnicodeDictStrategy(AbstractTypedStrategy, DictStrategy):
erase, unerase = rerased.new_erasing_pair("unicode")
erase = staticmethod(erase)
@@ -1052,9 +1052,9 @@
return space.is_w(space.type(w_obj), space.w_unicode)
def get_empty_storage(self):
- res = {}
- mark_dict_non_null(res)
- return self.erase(res)
+ new_dict = r_dict(Utf8Str.__eq__, Utf8Str.__hash__,
+ force_non_null=True)
+ return self.erase(new_dict)
def _never_equal_to(self, w_lookup_type):
return _never_equal_to_string(self.space, w_lookup_type)
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -2,6 +2,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.signature import Signature
from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.utf8 import Utf8Str
from pypy.objspace.std.bytesobject import W_BytesObject
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.stdtypedef import StdTypeDef
@@ -1250,10 +1251,14 @@
name='set(unicode).intersect')
def get_empty_storage(self):
- return self.erase({})
+ new_dict = r_dict(Utf8Str.__eq__, Utf8Str.__hash__,
+ force_non_null=True)
+ return self.erase(new_dict)
def get_empty_dict(self):
- return {}
+ new_dict = r_dict(Utf8Str.__eq__, Utf8Str.__hash__,
+ force_non_null=True)
+ return new_dict
def listview_unicode(self, w_set):
return self.unerase(w_set.sstorage).keys()
diff --git a/pypy/objspace/std/test/test_setobject.py
b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -109,9 +109,9 @@
w_set = W_SetObject(self.space)
_initialize_set(self.space, w_set, w_list)
assert w_set.strategy is self.space.fromcache(UnicodeSetStrategy)
- assert w_set.strategy.unerase(w_set.sstorage) == {Utf8Str("1") :None,
- Utf8Str("2") :None,
- Utf8Str("3") :None}
+ assert dict(w_set.strategy.unerase(w_set.sstorage)) == {Utf8Str("1")
:None,
+ Utf8Str("2")
:None,
+ Utf8Str("3")
:None}
w_list = W_ListObject(self.space, [w("1"), w(2), w("3")])
w_set = W_SetObject(self.space)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit