Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: unicode-utf8-py3
Changeset: r95626:e75259de9a45
Date: 2019-01-13 15:08 +0100
http://bitbucket.org/pypy/pypy/changeset/e75259de9a45/
Log: fix the kwargsdict problem
diff --git a/pypy/objspace/std/kwargsdict.py b/pypy/objspace/std/kwargsdict.py
--- a/pypy/objspace/std/kwargsdict.py
+++ b/pypy/objspace/std/kwargsdict.py
@@ -3,7 +3,7 @@
Based on two lists containing unwrapped key value pairs.
"""
-from rpython.rlib import jit, rerased, objectmodel
+from rpython.rlib import jit, rerased, objectmodel, rutf8
from pypy.objspace.std.dictmultiobject import (
DictStrategy, EmptyDictStrategy, ObjectDictStrategy, UnicodeDictStrategy,
@@ -149,11 +149,12 @@
strategy = self.space.fromcache(UnicodeDictStrategy)
keys, values_w = self.unerase(w_dict.dstorage)
storage = strategy.get_empty_storage()
- d_new = strategy.unerase(storage)
- for i in range(len(keys)):
- d_new[strategy.decodekey_str(keys[i])] = values_w[i]
w_dict.set_strategy(strategy)
w_dict.dstorage = storage
+ for i in range(len(keys)):
+ # NB: this can turn the dict into an object strategy, if a key is
+ # not ASCII!
+ w_dict.setitem_str(keys[i], values_w[i])
def view_as_kwargs(self, w_dict):
keys, values_w = self.unerase(w_dict.dstorage)
diff --git a/pypy/objspace/std/test/test_kwargsdict.py
b/pypy/objspace/std/test/test_kwargsdict.py
--- a/pypy/objspace/std/test/test_kwargsdict.py
+++ b/pypy/objspace/std/test/test_kwargsdict.py
@@ -76,6 +76,14 @@
assert d.get_strategy() is not strategy
assert "UnicodeDictStrategy" == d.get_strategy().__class__.__name__
+def test_limit_size_non_ascii():
+ storage = strategy.get_empty_storage()
+ d = W_DictObject(space, strategy, storage)
+ for i in range(100):
+ assert d.setitem_str("ה%s" % i, 4) is None
+ assert d.get_strategy() is not strategy
+ assert "ObjectDictStrategy" == d.get_strategy().__class__.__name__
+
def test_keys_doesnt_wrap():
space = FakeSpace()
space.newlist = None
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit