[pypy-svn] r37630 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jan 30 18:26:54 CET 2007


Author: arigo
Date: Tue Jan 30 18:26:51 2007
New Revision: 37630

Modified:
   pypy/dist/pypy/objspace/std/test/test_typeobject.py
   pypy/dist/pypy/objspace/std/typeobject.py
   pypy/dist/pypy/objspace/std/typetype.py
Log:
issue274 resolved

Hack in a different way to make __module__ behave more exactly like CPython.


Modified: pypy/dist/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_typeobject.py	Tue Jan 30 18:26:51 2007
@@ -708,9 +708,11 @@
         assert b.x == 3
 
     def test_module(self):
+        def f(): pass
         assert object.__module__ == '__builtin__'
         assert int.__module__ == '__builtin__'
         assert type.__module__ == '__builtin__'
+        assert type(f).__module__ == '__builtin__'
         d = {'__name__': 'yay'}
         exec """class A(object):\n  pass\n""" in d
         A = d['A']

Modified: pypy/dist/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typeobject.py	(original)
+++ pypy/dist/pypy/objspace/std/typeobject.py	Tue Jan 30 18:26:51 2007
@@ -6,6 +6,7 @@
 from pypy.objspace.std.stdtypedef import std_dict_descr, issubtypedef, Member
 from pypy.objspace.std.objecttype import object_typedef
 from pypy.objspace.std.dictproxyobject import W_DictProxyObject
+from pypy.rlib.objectmodel import we_are_translated
 
 from copy_reg import _HEAPTYPE
 
@@ -390,10 +391,17 @@
 
     def get_module(w_self):
         space = w_self.space
-        if (not space.is_w(w_self, space.w_type)    # hum
-            and '__module__' in w_self.dict_w):
+        if w_self.is_heaptype() and '__module__' in w_self.dict_w:
             return w_self.dict_w['__module__']
         else:
+            # for non-heap types, CPython checks for a module.name in the
+            # type name.  we skip that here and only provide the default
+            if not we_are_translated():
+                # hack for faked types
+                if ('__module__' in w_self.dict_w and
+                    space.is_true(space.isinstance(w_self.dict_w['__module__'],
+                                                   space.w_str))):
+                    return w_self.dict_w['__module__']
             return space.wrap('__builtin__')
 
     def add_subclass(w_self, w_subclass):

Modified: pypy/dist/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/typetype.py	(original)
+++ pypy/dist/pypy/objspace/std/typetype.py	Tue Jan 30 18:26:51 2007
@@ -224,18 +224,6 @@
     w_type = _check(space, w_type)    
     return space.wrap(w_type.__flags__)
 
-def defunct_descr_get__module(space, w_type):
-    if w_type.is_heaptype():
-        return w_type.dict_w['__module__']
-    else:
-        # here CPython checks for a module.name in the type description.
-        # we skip that here and only provide the default
-        return space.wrap('__builtin__')
-
-# heaptypeness is not really the right criteria, because we
-# also might get a module attribute from a faked type.
-# therefore, we use the module attribute whenever it exists.
-
 def descr_get__module(space, w_type):
     w_type = _check(space, w_type)
     return w_type.get_module()



More information about the Pypy-commit mailing list