Author: Armin Rigo <[email protected]>
Branch: refactor-str-types
Changeset: r65635:de6e41b763ad
Date: 2013-07-25 11:18 +0200
http://bitbucket.org/pypy/pypy/changeset/de6e41b763ad/
Log: For interp2app(), pick up the docstring from either the interp-level
function (as it was done before) or override it with the "doc"
keyword argument.
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -520,12 +520,13 @@
# When a BuiltinCode is stored in a Function object,
# you get the functionality of CPython's built-in function type.
- def __init__(self, func, unwrap_spec=None, self_type=None,
descrmismatch=None):
+ def __init__(self, func, unwrap_spec=None, self_type=None,
+ descrmismatch=None, doc=None):
"NOT_RPYTHON"
# 'implfunc' is the interpreter-level function.
# Note that this uses a lot of (construction-time) introspection.
Code.__init__(self, func.__name__)
- self.docstring = func.__doc__
+ self.docstring = doc or func.__doc__
self.identifier = "%s-%s-%s" % (func.__module__, func.__name__,
getattr(self_type, '__name__', '*'))
@@ -832,7 +833,7 @@
instancecache = {}
def __new__(cls, f, app_name=None, unwrap_spec=None, descrmismatch=None,
- as_classmethod=False):
+ as_classmethod=False, doc=None):
"NOT_RPYTHON"
# f must be a function whose name does NOT start with 'app_'
@@ -861,7 +862,8 @@
cls.instancecache[key] = self
self._code = BuiltinCode(f, unwrap_spec=unwrap_spec,
self_type=self_type,
- descrmismatch=descrmismatch)
+ descrmismatch=descrmismatch,
+ doc=doc)
self.__name__ = f.func_name
self.name = app_name
self.as_classmethod = as_classmethod
diff --git a/pypy/interpreter/test/test_gateway.py
b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -708,6 +708,18 @@
never_called
py.test.raises(AssertionError, space.wrap, gateway.interp2app_temp(g))
+ def test_interp2app_doc(self):
+ space = self.space
+ def f(space, w_x):
+ """foo"""
+ w_f = space.wrap(gateway.interp2app_temp(f))
+ assert space.unwrap(space.getattr(w_f, space.wrap('__doc__'))) == 'foo'
+ #
+ def g(space, w_x):
+ never_called
+ w_g = space.wrap(gateway.interp2app_temp(g, doc='bar'))
+ assert space.unwrap(space.getattr(w_g, space.wrap('__doc__'))) == 'bar'
+
class AppTestPyTestMark:
@py.test.mark.unlikely_to_exist
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit