2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00

libs/python/src/object/function.cpp: support __module__ attribute (to help certain doc generation systems)

[SVN r65555]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2010-09-23 19:22:12 +00:00
parent bd8a9eb1fd
commit 76af2cfc6b
3 changed files with 22 additions and 0 deletions

View File

@@ -39,6 +39,8 @@ struct BOOST_PYTHON_DECL function : PyObject
void doc(object const& x);
object const& name() const;
object const& get_namespace() const { return m_namespace; }
private: // helper functions
object signature(bool show_return_type=false) const;

View File

@@ -670,11 +670,26 @@ extern "C"
{
return python::incref(upcast<PyObject>(&PyCFunction_Type));
}
static PyObject* function_get_module(PyObject* op, void*)
{
function* f = downcast<function>(op);
object const& ns = f->get_namespace();
if (!ns.is_none()) {
return python::incref(ns.ptr());
}
PyErr_SetString(
PyExc_AttributeError, const_cast<char*>(
"Boost.Python function __module__ unknown."));
return 0;
}
}
static PyGetSetDef function_getsetlist[] = {
{const_cast<char*>("__name__"), (getter)function_get_name, 0, 0, 0 },
{const_cast<char*>("func_name"), (getter)function_get_name, 0, 0, 0 },
{const_cast<char*>("__module__"), (getter)function_get_module, 0, 0, 0 },
{const_cast<char*>("func_module"), (getter)function_get_module, 0, 0, 0 },
{const_cast<char*>("__class__"), (getter)function_get_class, 0, 0, 0 }, // see note above
{const_cast<char*>("__doc__"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},
{const_cast<char*>("func_doc"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},

View File

@@ -7,6 +7,11 @@
>>> print func.__doc__.splitlines()[1]
func( (A)arg1) -> A :
>>> print func.__module__
pytype_function_ext
>>> print func.__name__
func
"""
def run(args = None):
import sys