[pypy-svn] r75628 - in pypy/branch/fast-forward/pypy: interpreter objspace/std

benjamin at codespeak.net benjamin at codespeak.net
Mon Jun 28 06:05:04 CEST 2010


Author: benjamin
Date: Mon Jun 28 06:05:03 2010
New Revision: 75628

Modified:
   pypy/branch/fast-forward/pypy/interpreter/typedef.py
   pypy/branch/fast-forward/pypy/objspace/std/typeobject.py
   pypy/branch/fast-forward/pypy/objspace/std/typetype.py
Log:
make doc an attribute for builtin types

Modified: pypy/branch/fast-forward/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/fast-forward/pypy/interpreter/typedef.py	Mon Jun 28 06:05:03 2010
@@ -19,6 +19,7 @@
         self.base = __base
         self.hasdict = '__dict__' in rawdict
         self.weakrefable = '__weakref__' in rawdict
+        self.doc = rawdict.pop('__doc__', None)
         if __base is not None:
             self.hasdict     |= __base.hasdict
             self.weakrefable |= __base.weakrefable

Modified: pypy/branch/fast-forward/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/typeobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/typeobject.py	Mon Jun 28 06:05:03 2010
@@ -96,6 +96,7 @@
         w_self.hasdict = False
         w_self.needsdel = False
         w_self.weakrefable = False
+        w_self.w_doc = space.w_None
         w_self.weak_subclasses = []
         w_self.__flags__ = 0           # or _HEAPTYPE or _CPYTYPE
         w_self.instancetypedef = overridetypedef
@@ -594,11 +595,12 @@
 def setup_builtin_type(w_self):
     w_self.hasdict = w_self.instancetypedef.hasdict
     w_self.weakrefable = w_self.instancetypedef.weakrefable
+    w_self.w_doc = w_self.space.wrap(w_self.instancetypedef.doc)
     ensure_common_attributes(w_self)
 
 def ensure_common_attributes(w_self):
     ensure_static_new(w_self)
-    ensure_doc_attr(w_self)
+    w_self.dict_w.setdefault('__doc__', w_self.w_doc)
     if w_self.is_heaptype():
         ensure_module_attr(w_self)
     w_self.mro_w = []      # temporarily
@@ -612,10 +614,6 @@
         if isinstance(w_new, Function):
             w_self.dict_w['__new__'] = StaticMethod(w_new)
 
-def ensure_doc_attr(w_self):
-    # make sure there is a __doc__ in dict_w
-    w_self.dict_w.setdefault('__doc__', w_self.space.w_None)
-
 def ensure_module_attr(w_self):
     # initialize __module__ in the dict (user-defined types only)
     if '__module__' not in w_self.dict_w:

Modified: pypy/branch/fast-forward/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/typetype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/typetype.py	Mon Jun 28 06:05:03 2010
@@ -181,6 +181,8 @@
         return space.wrap("""type(object) -> the object's type
 type(name, bases, dict) -> a new type""")
     w_type = _check(space, w_type)
+    if not w_type.is_heaptype():
+        return w_type.w_doc
     w_result = w_type.getdictvalue(space, '__doc__')
     if w_result is None:
         return space.w_None



More information about the Pypy-commit mailing list