[pypy-svn] pypy new-dict-proxy: Fixed bug in W_TypeObject.get_module: we cannot directly read values from w_dict anymore

l.diekmann commits-noreply at bitbucket.org
Mon Apr 25 16:00:43 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: new-dict-proxy
Changeset: r43590:ab926f846f39
Date: 2011-04-25 16:00 +0200
http://bitbucket.org/pypy/pypy/changeset/ab926f846f39/

Log:	Fixed bug in W_TypeObject.get_module: we cannot directly read values
	from w_dict anymore

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
@@ -459,15 +459,15 @@
     def get_module(w_self):
         space = w_self.space
         if w_self.is_heaptype() and '__module__' in w_self.dict_w:
-            return w_self.dict_w['__module__']
+            return w_self.getdictvalue(space, '__module__')
         else:
             # for non-heap types, CPython checks for a module.name in the
             # type name.  That's a hack, so we're allowed to use a different
             # hack...
             if ('__module__' in w_self.dict_w and
-                space.is_true(space.isinstance(w_self.dict_w['__module__'],
+                space.is_true(space.isinstance(w_self.getdictvalue(space, '__module__'),
                                                space.w_str))):
-                return w_self.dict_w['__module__']
+                return w_self.getdictvalue(space, '__module__')
             return space.wrap('__builtin__')
 
     def get_module_type_name(w_self):

diff --git a/pypy/objspace/std/test/test_methodcache.py b/pypy/objspace/std/test/test_methodcache.py
--- a/pypy/objspace/std/test/test_methodcache.py
+++ b/pypy/objspace/std/test/test_methodcache.py
@@ -172,3 +172,8 @@
             setattr(a, "a%s" % i, i)
         cache_counter = __pypy__.method_cache_counter("x")
         assert cache_counter[0] == 0 # 0 hits, because all the attributes are new
+
+    def test_get_module_from_namedtuple(self):
+        # this used to crash
+        from collections import namedtuple
+        assert namedtuple("a", "b").__module__


More information about the Pypy-commit mailing list