[pypy-svn] r36432 - in pypy/dist/pypy: config interpreter objspace/std
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Jan 10 20:06:35 CET 2007
Author: cfbolz
Date: Wed Jan 10 20:06:34 2007
New Revision: 36432
Modified:
pypy/dist/pypy/config/pypyoption.py
pypy/dist/pypy/interpreter/typedef.py
pypy/dist/pypy/objspace/std/dictmultiobject.py
Log:
(pedronis, cfbolz): add "shadow tracking": you can ask an instance whether it
shadows an attribute of a class in the mro.
Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py (original)
+++ pypy/dist/pypy/config/pypyoption.py Wed Jan 10 20:06:34 2007
@@ -145,6 +145,14 @@
cmdline=None,
default=False),
+ BoolOption("withshadowtracking",
+ "track whether an instance attribute shadows a type"
+ " attribute",
+ cmdline=None,
+ default=False,
+ requires=[("objspace.std.withmultidict", True)]),
+
+
BoolOption("optimized_int_add",
"special case the addition of two integers in BINARY_ADD",
default=False),
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Wed Jan 10 20:06:34 2007
@@ -187,6 +187,12 @@
from pypy.objspace.std import dictmultiobject
self.w__dict__ = dictmultiobject.W_DictMultiObject(space,
sharing=True)
+ elif space.config.objspace.std.withshadowtracking:
+ from pypy.objspace.std import dictmultiobject
+ self.w__dict__ = dictmultiobject.W_DictMultiObject(space)
+ self.w__dict__.implementation = \
+ dictmultiobject.ShadowDetectingDictImplementation(
+ space, w_subtype)
else:
self.w__dict__ = space.newdict()
self.user_setup_slots(w_subtype.nslots)
Modified: pypy/dist/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictmultiobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictmultiobject.py Wed Jan 10 20:06:34 2007
@@ -94,6 +94,9 @@
w_key = self.space.wrap(OPTIMIZED_BUILTINS[i])
return self.get(w_key)
+# this attribute will only be seen whan a certain config option is used
+ shadows_anything = True
+
# Iterator Implementation base classes
@@ -491,6 +494,30 @@
return None
+class ShadowDetectingDictImplementation(StrDictImplementation):
+ def __init__(self, space, w_type):
+ StrDictImplementation.__init__(self, space)
+ self.w_type = w_type
+ self.shadows_anything = False
+
+ def setitem_str(self, w_key, w_value, shadows_type=True):
+ if shadows_type:
+ self.shadows_anything = True
+ return StrDictImplementation.setitem_str(
+ self, w_key, w_value, shadows_type)
+
+ def setitem(self, w_key, w_value):
+ space = self.space
+ if space.is_w(space.type(w_key), space.w_str):
+ if not self.shadows_anything:
+ w_obj = self.w_type.lookup(space.str_w(w_key))
+ if w_obj is not None:
+ self.shadows_anything = True
+ return StrDictImplementation.setitem_str(
+ self, w_key, w_value, False)
+ else:
+ return self._as_rdict().setitem(w_key, w_value)
+
class WaryDictImplementation(StrDictImplementation):
def __init__(self, space):
StrDictImplementation.__init__(self, space)
More information about the Pypy-commit
mailing list