[pypy-commit] pypy globals-quasiimmut: introduce a special class W_ModuleDictObject which stores the strategy as a
cfbolz
pypy.commits at gmail.com
Wed Jan 13 15:46:47 EST 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: globals-quasiimmut
Changeset: r81748:bccc7eeb61f9
Date: 2016-01-13 21:40 +0100
http://bitbucket.org/pypy/pypy/changeset/bccc7eeb61f9/
Log: introduce a special class W_ModuleDictObject which stores the
strategy as a quasi-immutable field. that way, global lookups really
produce 0 ops, even in the preamble.
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -93,7 +93,7 @@
Return the underlying strategy currently used by a dict, list or set object
"""
if isinstance(w_obj, W_DictMultiObject):
- name = w_obj.strategy.__class__.__name__
+ name = w_obj.get_strategy().__class__.__name__
elif isinstance(w_obj, W_ListObject):
name = w_obj.strategy.__class__.__name__
elif isinstance(w_obj, W_BaseSetObject):
diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -153,7 +153,7 @@
d_new = strategy.unerase(strategy.get_empty_storage())
for key, cell in d.iteritems():
d_new[_wrapkey(space, key)] = unwrap_cell(self.space, cell)
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = strategy.erase(d_new)
def getiterkeys(self, w_dict):
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
@@ -42,6 +42,14 @@
class W_DictMultiObject(W_Root):
+ """ Abstract base class that does not store a strategy. """
+ def get_strategy(self):
+ raise NotImplementedError("abstract method")
+
+ def set_strategy(self, strategy):
+ raise NotImplementedError("abstract method")
+
+
@staticmethod
def allocate_and_init_instance(space, w_type=None, module=False,
instance=False, strdict=False,
@@ -52,6 +60,10 @@
# every module needs its own strategy, because the strategy stores
# the version tag
strategy = ModuleDictStrategy(space)
+ storage = strategy.get_empty_storage()
+ w_obj = space.allocate_instance(W_ModuleDictObject, space.w_dict)
+ W_ModuleDictObject.__init__(w_obj, space, strategy, storage)
+ return w_obj
elif space.config.objspace.std.withmapdict and instance:
from pypy.objspace.std.mapdict import MapDictStrategy
strategy = space.fromcache(MapDictStrategy)
@@ -68,18 +80,17 @@
w_type = space.w_dict
storage = strategy.get_empty_storage()
- w_obj = space.allocate_instance(W_DictMultiObject, w_type)
- W_DictMultiObject.__init__(w_obj, space, strategy, storage)
+ w_obj = space.allocate_instance(W_DictObject, w_type)
+ W_DictObject.__init__(w_obj, space, strategy, storage)
return w_obj
- def __init__(self, space, strategy, storage):
+ def __init__(self, space, storage):
self.space = space
- self.strategy = strategy
self.dstorage = storage
def __repr__(self):
"""representation for debugging purposes"""
- return "%s(%s)" % (self.__class__.__name__, self.strategy)
+ return "%s(%s)" % (self.__class__.__name__, self.get_strategy())
def unwrap(w_dict, space):
result = {}
@@ -101,7 +112,7 @@
self.setitem(w_k, w_v)
def setitem_str(self, key, w_value):
- self.strategy.setitem_str(self, key, w_value)
+ self.get_strategy().setitem_str(self, key, w_value)
@staticmethod
def descr_new(space, w_dicttype, __args__):
@@ -261,8 +272,9 @@
def nondescr_reversed_dict(self, space):
"""Not exposed directly to app-level, but via __pypy__.reversed_dict().
"""
- if self.strategy.has_iterreversed:
- it = self.strategy.iterreversed(self)
+ strategy = self.get_strategy()
+ if strategy.has_iterreversed:
+ it = strategy.iterreversed(self)
return W_DictMultiIterKeysObject(space, it)
else:
# fall-back
@@ -337,6 +349,37 @@
init_or_update(space, self, __args__, 'dict.update')
+class W_DictObject(W_DictMultiObject):
+ """ a regular dict object """
+ def __init__(self, space, strategy, storage):
+ W_DictMultiObject.__init__(self, space, storage)
+ self.dstrategy = strategy
+
+ def get_strategy(self):
+ return self.dstrategy
+
+ def set_strategy(self, strategy):
+ self.dstrategy = strategy
+
+
+class W_ModuleDictObject(W_DictMultiObject):
+ """ a dict object for a module, that is not expected to change. It stores
+ the strategy as a quasi-immutable field. """
+ _immutable_fields_ = ['mstrategy?']
+
+ def __init__(self, space, strategy, storage):
+ W_DictMultiObject.__init__(self, space, storage)
+ self.mstrategy = strategy
+
+ def get_strategy(self):
+ return self.mstrategy
+
+ def set_strategy(self, strategy):
+ self.mstrategy = strategy
+
+
+
+
def _add_indirections():
dict_methods = "getitem getitem_str setitem setdefault \
popitem delitem clear \
@@ -347,7 +390,7 @@
def make_method(method):
def f(self, *args):
- return getattr(self.strategy, method)(self, *args)
+ return getattr(self.get_strategy(), method)(self, *args)
f.func_name = method
return f
@@ -490,7 +533,7 @@
def clear(self, w_dict):
strategy = self.space.fromcache(EmptyDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def listview_bytes(self, w_dict):
@@ -556,32 +599,32 @@
def switch_to_bytes_strategy(self, w_dict):
strategy = self.space.fromcache(BytesDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def switch_to_unicode_strategy(self, w_dict):
strategy = self.space.fromcache(UnicodeDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def switch_to_int_strategy(self, w_dict):
strategy = self.space.fromcache(IntDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def switch_to_identity_strategy(self, w_dict):
from pypy.objspace.std.identitydict import IdentityDictStrategy
strategy = self.space.fromcache(IdentityDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def switch_to_object_strategy(self, w_dict):
strategy = self.space.fromcache(ObjectDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def getitem(self, w_dict, w_key):
@@ -662,7 +705,7 @@
if self.pos < self.len:
result = getattr(self, 'next_' + TP + '_entry')()
self.pos += 1
- if self.strategy is self.dictimplementation.strategy:
+ if self.strategy is self.dictimplementation.get_strategy():
return result # common case
else:
# waaa, obscure case: the strategy changed, but not the
@@ -804,7 +847,7 @@
else:
return # w_dict is completely empty, nothing to do
count = w_dict.length() - 1
- w_updatedict.strategy.prepare_update(w_updatedict, count)
+ w_updatedict.get_strategy().prepare_update(w_updatedict, count)
# If the strategy is still different, continue the slow way
if not same_strategy(self, w_updatedict):
for key, value, keyhash in iteritemsh:
@@ -825,7 +868,7 @@
def same_strategy(self, w_otherdict):
return (setitem_untyped is not None and
- w_otherdict.strategy is self)
+ w_otherdict.get_strategy() is self)
dictimpl.iterkeys = iterkeys
dictimpl.itervalues = itervalues
@@ -934,7 +977,7 @@
d_new = strategy.unerase(strategy.get_empty_storage())
for key, value in d.iteritems():
d_new[self.wrap(key)] = value
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = strategy.erase(d_new)
# --------------- iterator interface -----------------
@@ -1178,7 +1221,7 @@
def update1_dict_dict(space, w_dict, w_data):
- w_data.strategy.rev_update1_dict_dict(w_data, w_dict)
+ w_data.get_strategy().rev_update1_dict_dict(w_data, w_dict)
def update1_pairs(space, w_dict, data_w):
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
@@ -18,7 +18,7 @@
def switch_to_bytes_strategy(self, w_dict):
strategy = self.space.fromcache(KwargsDictStrategy)
storage = strategy.get_empty_storage()
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
@@ -142,7 +142,7 @@
d_new = strategy.unerase(strategy.get_empty_storage())
for i in range(len(keys)):
d_new[self.wrap(keys[i])] = values_w[i]
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = strategy.erase(d_new)
def switch_to_bytes_strategy(self, w_dict):
@@ -152,7 +152,7 @@
d_new = strategy.unerase(storage)
for i in range(len(keys)):
d_new[keys[i]] = values_w[i]
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = storage
def view_as_kwargs(self, w_dict):
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -6,7 +6,8 @@
from pypy.interpreter.baseobjspace import W_Root
from pypy.objspace.std.dictmultiobject import (
W_DictMultiObject, DictStrategy, ObjectDictStrategy, BaseKeyIterator,
- BaseValueIterator, BaseItemIterator, _never_equal_to_string
+ BaseValueIterator, BaseItemIterator, _never_equal_to_string,
+ W_DictObject,
)
from pypy.objspace.std.typeobject import MutableCell
@@ -407,7 +408,7 @@
strategy = space.fromcache(MapDictStrategy)
storage = strategy.erase(self)
- w_dict = W_DictMultiObject(space, strategy, storage)
+ w_dict = W_DictObject(space, strategy, storage)
flag = self._get_mapdict_map().write(self, ("dict", SPECIAL), w_dict)
assert flag
return w_dict
@@ -422,8 +423,8 @@
# new dict. If the old dict was using the MapDictStrategy, we
# have to force it now: otherwise it would remain an empty
# shell that continues to delegate to 'self'.
- if type(w_olddict.strategy) is MapDictStrategy:
- w_olddict.strategy.switch_to_object_strategy(w_olddict)
+ if type(w_olddict.get_strategy()) is MapDictStrategy:
+ w_olddict.get_strategy().switch_to_object_strategy(w_olddict)
flag = self._get_mapdict_map().write(self, ("dict", SPECIAL), w_dict)
assert flag
@@ -641,7 +642,7 @@
w_obj = self.unerase(w_dict.dstorage)
strategy = self.space.fromcache(ObjectDictStrategy)
dict_w = strategy.unerase(strategy.get_empty_storage())
- w_dict.strategy = strategy
+ w_dict.set_strategy(strategy)
w_dict.dstorage = strategy.erase(dict_w)
assert w_obj.getdict(self.space) is w_dict or w_obj._get_mapdict_map().terminator.w_cls is None
materialize_r_dict(self.space, w_obj, dict_w)
@@ -750,7 +751,7 @@
def next_key_entry(self):
implementation = self.dictimplementation
- assert isinstance(implementation.strategy, MapDictStrategy)
+ assert isinstance(implementation.get_strategy(), MapDictStrategy)
if self.orig_map is not self.w_obj._get_mapdict_map():
return None
if self.curr_map:
@@ -772,7 +773,7 @@
def next_value_entry(self):
implementation = self.dictimplementation
- assert isinstance(implementation.strategy, MapDictStrategy)
+ assert isinstance(implementation.get_strategy(), MapDictStrategy)
if self.orig_map is not self.w_obj._get_mapdict_map():
return None
if self.curr_map:
@@ -793,7 +794,7 @@
def next_item_entry(self):
implementation = self.dictimplementation
- assert isinstance(implementation.strategy, MapDictStrategy)
+ assert isinstance(implementation.get_strategy(), MapDictStrategy)
if self.orig_map is not self.w_obj._get_mapdict_map():
return None, None
if self.curr_map:
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -18,7 +18,7 @@
from pypy.objspace.std.bytearrayobject import W_BytearrayObject
from pypy.objspace.std.bytesobject import W_AbstractBytesObject, W_BytesObject, wrapstr
from pypy.objspace.std.complexobject import W_ComplexObject
-from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+from pypy.objspace.std.dictmultiobject import W_DictMultiObject, W_DictObject
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.intobject import W_IntObject, setup_prebuilt, wrapint
from pypy.objspace.std.iterobject import W_AbstractSeqIterObject, W_SeqIterObject
@@ -439,7 +439,7 @@
# and isinstance() for others. See test_listobject.test_uses_custom...
if type(w_obj) is W_ListObject:
return w_obj.getitems_bytes()
- if type(w_obj) is W_DictMultiObject:
+ if type(w_obj) is W_DictObject:
return w_obj.listview_bytes()
if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
return w_obj.listview_bytes()
@@ -454,7 +454,7 @@
# and isinstance() for others. See test_listobject.test_uses_custom...
if type(w_obj) is W_ListObject:
return w_obj.getitems_unicode()
- if type(w_obj) is W_DictMultiObject:
+ if type(w_obj) is W_DictObject:
return w_obj.listview_unicode()
if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
return w_obj.listview_unicode()
@@ -467,7 +467,7 @@
def listview_int(self, w_obj):
if type(w_obj) is W_ListObject:
return w_obj.getitems_int()
- if type(w_obj) is W_DictMultiObject:
+ if type(w_obj) is W_DictObject:
return w_obj.listview_int()
if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
return w_obj.listview_int()
@@ -485,7 +485,7 @@
return None
def view_as_kwargs(self, w_dict):
- if type(w_dict) is W_DictMultiObject:
+ if type(w_dict) is W_DictObject:
return w_dict.view_as_kwargs()
return (None, None)
diff --git a/pypy/objspace/std/test/test_celldict.py b/pypy/objspace/std/test/test_celldict.py
--- a/pypy/objspace/std/test/test_celldict.py
+++ b/pypy/objspace/std/test/test_celldict.py
@@ -1,7 +1,7 @@
import py
from pypy.objspace.std.celldict import ModuleDictStrategy
-from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+from pypy.objspace.std.dictmultiobject import W_DictObject, W_ModuleDictObject
from pypy.objspace.std.test.test_dictmultiobject import (
BaseTestRDictImplementation, BaseTestDevolvedDictImplementation, FakeSpace,
FakeString)
@@ -14,7 +14,7 @@
def test_basic_property_cells(self):
strategy = ModuleDictStrategy(space)
storage = strategy.get_empty_storage()
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_ModuleDictObject(space, strategy, storage)
v1 = strategy.version
key = "a"
@@ -23,30 +23,30 @@
v2 = strategy.version
assert v1 is not v2
assert d.getitem(w_key) == 1
- assert d.strategy.getdictvalue_no_unwrapping(d, key) == 1
+ assert d.get_strategy().getdictvalue_no_unwrapping(d, key) == 1
d.setitem(w_key, 2)
v3 = strategy.version
assert v2 is not v3
assert d.getitem(w_key) == 2
- assert d.strategy.getdictvalue_no_unwrapping(d, key).w_value == 2
+ assert d.get_strategy().getdictvalue_no_unwrapping(d, key).w_value == 2
d.setitem(w_key, 3)
v4 = strategy.version
assert v3 is v4
assert d.getitem(w_key) == 3
- assert d.strategy.getdictvalue_no_unwrapping(d, key).w_value == 3
+ assert d.get_strategy().getdictvalue_no_unwrapping(d, key).w_value == 3
d.delitem(w_key)
v5 = strategy.version
assert v5 is not v4
assert d.getitem(w_key) is None
- assert d.strategy.getdictvalue_no_unwrapping(d, key) is None
+ assert d.get_strategy().getdictvalue_no_unwrapping(d, key) is None
def test_same_key_set_twice(self):
strategy = ModuleDictStrategy(space)
storage = strategy.get_empty_storage()
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_ModuleDictObject(space, strategy, storage)
v1 = strategy.version
x = object()
@@ -134,7 +134,7 @@
py.test.skip("__repr__ doesn't work on appdirect")
strategy = ModuleDictStrategy(cls.space)
storage = strategy.get_empty_storage()
- cls.w_d = W_DictMultiObject(cls.space, strategy, storage)
+ cls.w_d = W_ModuleDictObject(cls.space, strategy, storage)
def test_popitem(self):
import __pypy__
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -2,14 +2,14 @@
import py
from pypy.objspace.std.dictmultiobject import (W_DictMultiObject,
- BytesDictStrategy, ObjectDictStrategy)
+ W_DictObject, BytesDictStrategy, ObjectDictStrategy)
class TestW_DictObject(object):
def test_empty(self):
d = self.space.newdict()
assert not self.space.is_true(d)
- assert type(d.strategy) is not ObjectDictStrategy
+ assert type(d.get_strategy()) is not ObjectDictStrategy
def test_nonempty(self):
space = self.space
@@ -1050,7 +1050,7 @@
return l
def newlist_bytes(self, l):
return l
- DictObjectCls = W_DictMultiObject
+ DictObjectCls = W_DictObject
def type(self, w_obj):
if isinstance(w_obj, FakeString):
return str
@@ -1076,7 +1076,7 @@
return tuple(l)
def newdict(self, module=False, instance=False):
- return W_DictMultiObject.allocate_and_init_instance(
+ return W_DictObject.allocate_and_init_instance(
self, module=module, instance=instance)
def view_as_kwargs(self, w_d):
@@ -1105,7 +1105,7 @@
w_float = float
StringObjectCls = FakeString
UnicodeObjectCls = FakeUnicode
- w_dict = W_DictMultiObject
+ w_dict = W_DictObject
iter = iter
fixedview = list
listview = list
@@ -1149,8 +1149,8 @@
def get_impl(self):
strategy = self.StrategyClass(self.fakespace)
storage = strategy.get_empty_storage()
- w_dict = self.fakespace.allocate_instance(W_DictMultiObject, None)
- W_DictMultiObject.__init__(w_dict, self.fakespace, strategy, storage)
+ w_dict = self.fakespace.allocate_instance(W_DictObject, None)
+ W_DictObject.__init__(w_dict, self.fakespace, strategy, storage)
return w_dict
def fill_impl(self):
@@ -1159,7 +1159,7 @@
def check_not_devolved(self):
#XXX check if strategy changed!?
- assert type(self.impl.strategy) is self.StrategyClass
+ assert type(self.impl.get_strategy()) is self.StrategyClass
#assert self.impl.r_dict_content is None
def test_popitem(self):
@@ -1246,7 +1246,7 @@
for x in xrange(100):
impl.setitem(self.fakespace.str_w(str(x)), x)
impl.setitem(x, x)
- assert type(impl.strategy) is ObjectDictStrategy
+ assert type(impl.get_strategy()) is ObjectDictStrategy
def test_setdefault_fast(self):
on_pypy = "__pypy__" in sys.builtin_module_names
@@ -1308,7 +1308,7 @@
class BaseTestDevolvedDictImplementation(BaseTestRDictImplementation):
def fill_impl(self):
BaseTestRDictImplementation.fill_impl(self)
- self.impl.strategy.switch_to_object_strategy(self.impl)
+ self.impl.get_strategy().switch_to_object_strategy(self.impl)
def check_not_devolved(self):
pass
@@ -1320,5 +1320,5 @@
def test_module_uses_strdict():
fakespace = FakeSpace()
d = fakespace.newdict(module=True)
- assert type(d.strategy) is BytesDictStrategy
+ assert type(d.get_strategy()) is BytesDictStrategy
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
@@ -1,5 +1,5 @@
import py
-from pypy.objspace.std.test.test_dictmultiobject import FakeSpace, W_DictMultiObject
+from pypy.objspace.std.test.test_dictmultiobject import FakeSpace, W_DictObject
from pypy.objspace.std.kwargsdict import *
space = FakeSpace()
@@ -9,7 +9,7 @@
keys = ["a", "b", "c"]
values = [1, 2, 3]
storage = strategy.erase((keys, values))
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
assert d.getitem_str("a") == 1
assert d.getitem_str("b") == 2
assert d.getitem_str("c") == 3
@@ -23,7 +23,7 @@
keys = ["a", "b", "c"]
values = [1, 2, 3]
storage = strategy.erase((keys, values))
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
assert d.getitem_str("a") == 1
assert d.getitem_str("b") == 2
assert d.getitem_str("c") == 3
@@ -52,7 +52,7 @@
keys = ["a", "b", "c"]
values = [1, 2, 3]
storage = strategy.erase((keys, values))
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
assert d.getitem_str("a") == 1
assert d.getitem_str("b") == 2
assert d.getitem_str("c") == 3
@@ -69,11 +69,11 @@
def test_limit_size():
storage = strategy.get_empty_storage()
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
for i in range(100):
assert d.setitem_str("d%s" % i, 4) is None
- assert d.strategy is not strategy
- assert "BytesDictStrategy" == d.strategy.__class__.__name__
+ assert d.get_strategy() is not strategy
+ assert "BytesDictStrategy" == d.get_strategy().__class__.__name__
def test_keys_doesnt_wrap():
space = FakeSpace()
@@ -82,7 +82,7 @@
keys = ["a", "b", "c"]
values = [1, 2, 3]
storage = strategy.erase((keys, values))
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
w_l = d.w_keys() # does not crash
def test_view_as_kwargs():
@@ -91,26 +91,27 @@
keys = ["a", "b", "c"]
values = [1, 2, 3]
storage = strategy.erase((keys, values))
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
assert (space.view_as_kwargs(d) == keys, values)
strategy = EmptyDictStrategy(space)
storage = strategy.get_empty_storage()
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
assert (space.view_as_kwargs(d) == [], [])
def test_from_empty_to_kwargs():
strategy = EmptyKwargsDictStrategy(space)
storage = strategy.get_empty_storage()
- d = W_DictMultiObject(space, strategy, storage)
+ d = W_DictObject(space, strategy, storage)
d.setitem_str("a", 3)
- assert isinstance(d.strategy, KwargsDictStrategy)
+ assert isinstance(d.get_strategy(), KwargsDictStrategy)
from pypy.objspace.std.test.test_dictmultiobject import BaseTestRDictImplementation, BaseTestDevolvedDictImplementation
def get_impl(self):
storage = strategy.erase(([], []))
- return W_DictMultiObject(space, strategy, storage)
+ return W_DictObject(space, strategy, storage)
+
class TestKwargsDictImplementation(BaseTestRDictImplementation):
StrategyClass = KwargsDictStrategy
get_impl = get_impl
diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -1,4 +1,4 @@
-from pypy.objspace.std.test.test_dictmultiobject import FakeSpace, W_DictMultiObject
+from pypy.objspace.std.test.test_dictmultiobject import FakeSpace, W_DictObject
from pypy.objspace.std.mapdict import *
class Config:
@@ -309,7 +309,7 @@
obj.setdictvalue(space, "c", 7)
assert obj.storage == [50, 60, 70, 5, 6, 7]
- class FakeDict(W_DictMultiObject):
+ class FakeDict(W_DictObject):
def __init__(self, d):
self.dstorage = d
@@ -368,7 +368,7 @@
def devolve_dict(space, obj):
w_d = obj.getdict(space)
- w_d.strategy.switch_to_object_strategy(w_d)
+ w_d.get_strategy().switch_to_object_strategy(w_d)
def test_get_setdictvalue_after_devolve():
cls = Class()
@@ -1127,7 +1127,7 @@
def test_newdict_instance():
w_dict = space.newdict(instance=True)
- assert type(w_dict.strategy) is MapDictStrategy
+ assert type(w_dict.get_strategy()) is MapDictStrategy
class TestMapDictImplementationUsingnewdict(BaseTestRDictImplementation):
StrategyClass = MapDictStrategy
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -478,12 +478,12 @@
def getdict(w_self, space): # returning a dict-proxy!
from pypy.objspace.std.dictproxyobject import DictProxyStrategy
- from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+ from pypy.objspace.std.dictmultiobject import W_DictObject
if w_self.lazyloaders:
w_self._cleanup_() # force un-lazification
strategy = space.fromcache(DictProxyStrategy)
storage = strategy.erase(w_self)
- return W_DictMultiObject(space, strategy, storage)
+ return W_DictObject(space, strategy, storage)
def is_heaptype(w_self):
return w_self.flag_heaptype
More information about the pypy-commit
mailing list