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:
@@ -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;
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user