Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65555 - in trunk: boost/python/object libs/python/src/object libs/python/test
From: rwgk_at_[hidden]
Date: 2010-09-23 15:22:14


Author: rwgk
Date: 2010-09-23 15:22:12 EDT (Thu, 23 Sep 2010)
New Revision: 65555
URL: http://svn.boost.org/trac/boost/changeset/65555

Log:
libs/python/src/object/function.cpp: support __module__ attribute (to help certain doc generation systems)
Text files modified:
   trunk/boost/python/object/function.hpp | 2 ++
   trunk/libs/python/src/object/function.cpp | 15 +++++++++++++++
   trunk/libs/python/test/pytype_function.py | 5 +++++
   3 files changed, 22 insertions(+), 0 deletions(-)

Modified: trunk/boost/python/object/function.hpp
==============================================================================
--- trunk/boost/python/object/function.hpp (original)
+++ trunk/boost/python/object/function.hpp 2010-09-23 15:22:12 EDT (Thu, 23 Sep 2010)
@@ -39,6 +39,8 @@
     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;

Modified: trunk/libs/python/src/object/function.cpp
==============================================================================
--- trunk/libs/python/src/object/function.cpp (original)
+++ trunk/libs/python/src/object/function.cpp 2010-09-23 15:22:12 EDT (Thu, 23 Sep 2010)
@@ -670,11 +670,26 @@
     {
         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},

Modified: trunk/libs/python/test/pytype_function.py
==============================================================================
--- trunk/libs/python/test/pytype_function.py (original)
+++ trunk/libs/python/test/pytype_function.py 2010-09-23 15:22:12 EDT (Thu, 23 Sep 2010)
@@ -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


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk