[pypy-svn] r48867 - pypy/dist/pypy/interpreter

fijal at codespeak.net fijal at codespeak.net
Tue Nov 20 19:46:30 CET 2007


Author: fijal
Date: Tue Nov 20 19:46:30 2007
New Revision: 48867

Modified:
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/typedef.py
Log:
Missing attributes to make StaticMethod a first-class member


Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Tue Nov 20 19:46:30 2007
@@ -461,6 +461,9 @@
         """staticmethod(x).__get__(obj[, type]) -> x"""
         return self.w_function
 
+    def descr_staticmethod__new__(space, w_type, w_function):
+        return space.wrap(StaticMethod(w_function))
+
 class BuiltinFunction(Function):
 
     def __init__(self, func):

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Tue Nov 20 19:46:30 2007
@@ -677,7 +677,22 @@
     )
 
 StaticMethod.typedef = TypeDef("staticmethod",
+    __doc__ = """staticmethod(function) -> static method
+
+Convert a function to be a static method.
+
+A static method does not receive an implicit first argument.
+To declare a static method, use this idiom:
+
+     class C:
+         def f(arg1, arg2, ...): ...
+         f = staticmethod(f)
+
+It can be called either on the class (e.g. C.f()) or on an instance
+(e.g. C().f()).  The instance is ignored except for its class.""",
     __get__ = interp2app(StaticMethod.descr_staticmethod_get),
+    __new__ = interp2app(StaticMethod.descr_staticmethod__new__.im_func,
+                         unwrap_spec = [ObjSpace, W_Root, W_Root]),
     )
 
 def always_none(self, obj):



More information about the Pypy-commit mailing list