[pypy-svn] pypy default: (fijal, arigo)
arigo
commits-noreply at bitbucket.org
Thu Jan 20 13:24:40 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r40986:853fe8de1524
Date: 2011-01-20 13:24 +0100
http://bitbucket.org/pypy/pypy/changeset/853fe8de1524/
Log: (fijal, arigo)
If the __dict__ of the class has already a '__dict__' or a
'__weakref__', don't hide it.
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -651,6 +651,13 @@
assert round(-(5e15-1)) == -(5e15-1)
assert round(-5e15) == -5e15
+ def test_vars_obscure_case(self):
+ class C_get_vars(object):
+ def getDict(self):
+ return {'a':2}
+ __dict__ = property(fget=getDict)
+ assert vars(C_get_vars()) == {'a':2}
+
class TestInternal:
def test_execfile(self, space):
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -978,6 +978,15 @@
assert ("x", 1) in d.items()
assert ("y", 2) in d.items()
+ def test_type_descriptors_overridden(self):
+ class A(object):
+ __dict__ = 42
+ assert A().__dict__ == 42
+ #
+ class B(object):
+ __weakref__ = 42
+ assert B().__weakref__ == 42
+
class AppTestMutableBuiltintypes:
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
@@ -599,12 +599,14 @@
def create_dict_slot(w_self):
if not w_self.hasdict:
- w_self.dict_w['__dict__'] = w_self.space.wrap(std_dict_descr)
+ w_self.dict_w.setdefault('__dict__',
+ w_self.space.wrap(std_dict_descr))
w_self.hasdict = True
def create_weakref_slot(w_self):
if not w_self.weakrefable:
- w_self.dict_w['__weakref__'] = w_self.space.wrap(weakref_descr)
+ w_self.dict_w.setdefault('__weakref__',
+ w_self.space.wrap(weakref_descr))
w_self.weakrefable = True
def valid_slot_name(slot_name):
More information about the Pypy-commit
mailing list