mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
Add generated docstrings to property fget/fset
This commit is contained in:
committed by
Stefan Seefeld
parent
d1910f3d65
commit
4c6f40fb82
@@ -372,10 +372,11 @@ class class_ : public objects::class_base
|
||||
{
|
||||
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
|
||||
|
||||
return this->make_fn_impl(
|
||||
return objects::add_doc(
|
||||
this->make_fn_impl(
|
||||
detail::unwrap_wrapper((W*)0)
|
||||
, f, is_obj_or_proxy(), (char*)0, detail::is_data_member_pointer<F>()
|
||||
);
|
||||
), NULL);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
@@ -383,10 +384,11 @@ class class_ : public objects::class_base
|
||||
{
|
||||
typedef typename api::is_object_operators<F>::type is_obj_or_proxy;
|
||||
|
||||
return this->make_fn_impl(
|
||||
return objects::add_doc(
|
||||
this->make_fn_impl(
|
||||
detail::unwrap_wrapper((W*)0)
|
||||
, f, is_obj_or_proxy(), (int*)0, detail::is_data_member_pointer<F>()
|
||||
);
|
||||
), NULL);
|
||||
}
|
||||
|
||||
template <class T, class F>
|
||||
|
||||
@@ -18,6 +18,8 @@ BOOST_PYTHON_DECL void add_to_namespace(
|
||||
BOOST_PYTHON_DECL void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute, char const* doc);
|
||||
|
||||
BOOST_PYTHON_DECL object const& add_doc(object const& attribute, char const* doc);
|
||||
|
||||
}}} // namespace boost::python::objects
|
||||
|
||||
#endif // ADD_TO_NAMESPACE_DWA200286_HPP
|
||||
|
||||
@@ -35,6 +35,8 @@ struct BOOST_PYTHON_DECL function : PyObject
|
||||
static void add_to_namespace(
|
||||
object const& name_space, char const* name, object const& attribute, char const* doc);
|
||||
|
||||
static object const& add_doc(object const& attribute, char const* doc);
|
||||
|
||||
object const& doc() const;
|
||||
void doc(object const& x);
|
||||
|
||||
|
||||
@@ -419,6 +419,30 @@ namespace detail
|
||||
extern char cpp_signature_tag[];
|
||||
}
|
||||
|
||||
object const& function::add_doc(object const& attribute, char const* doc)
|
||||
{
|
||||
str _doc;
|
||||
|
||||
if (docstring_options::show_py_signatures_)
|
||||
{
|
||||
_doc += str(const_cast<const char*>(detail::py_signature_tag));
|
||||
}
|
||||
if (doc != 0 && docstring_options::show_user_defined_)
|
||||
_doc += doc;
|
||||
|
||||
if (docstring_options::show_cpp_signatures_)
|
||||
{
|
||||
_doc += str(const_cast<const char*>(detail::cpp_signature_tag));
|
||||
}
|
||||
if(_doc)
|
||||
{
|
||||
object mutable_attribute(attribute);
|
||||
mutable_attribute.attr("__doc__")= _doc;
|
||||
}
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
void function::add_to_namespace(
|
||||
object const& name_space, char const* name_, object const& attribute, char const* doc)
|
||||
{
|
||||
@@ -545,24 +569,7 @@ void function::add_to_namespace(
|
||||
"C++ signature:", f->signature(true)));
|
||||
}
|
||||
*/
|
||||
str _doc;
|
||||
|
||||
if (docstring_options::show_py_signatures_)
|
||||
{
|
||||
_doc += str(const_cast<const char*>(detail::py_signature_tag));
|
||||
}
|
||||
if (doc != 0 && docstring_options::show_user_defined_)
|
||||
_doc += doc;
|
||||
|
||||
if (docstring_options::show_cpp_signatures_)
|
||||
{
|
||||
_doc += str(const_cast<const char*>(detail::cpp_signature_tag));
|
||||
}
|
||||
if(_doc)
|
||||
{
|
||||
object mutable_attribute(attribute);
|
||||
mutable_attribute.attr("__doc__")= _doc;
|
||||
}
|
||||
add_doc(attribute, doc);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL void add_to_namespace(
|
||||
@@ -577,6 +584,11 @@ BOOST_PYTHON_DECL void add_to_namespace(
|
||||
function::add_to_namespace(name_space, name, attribute, doc);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_DECL object const& add_doc(object const& attribute, char const* doc)
|
||||
{
|
||||
return function::add_doc(attribute, doc);
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -64,6 +64,7 @@ BOOST_PYTHON_MODULE(properties_ext)
|
||||
class_<X>("X", init<int>() )
|
||||
//defining read only property
|
||||
.add_property( "value_r", &X::get_value )
|
||||
.add_property( "value_r_f", make_function(&X::get_value) )
|
||||
.add_property( "value_r_ds", &X::get_value, "value_r_ds is read-only")
|
||||
//defining read \ write property
|
||||
.add_property( "value_rw", &X::get_value, &X::set_value )
|
||||
|
||||
@@ -20,6 +20,9 @@ value read only
|
||||
>>> x1.value_r
|
||||
1
|
||||
|
||||
>>> x1.value_r_f
|
||||
1
|
||||
|
||||
value read - write
|
||||
>>> x1.value_rw
|
||||
1
|
||||
@@ -84,8 +87,27 @@ after creating second intstance of X instances count is 2
|
||||
|
||||
>>> assert properties.X.value_rw_ds.__doc__ == "value_rw_ds is read-write"
|
||||
|
||||
>>> properties.X.value_r_f.fget.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1) -> int :'
|
||||
|
||||
>>> properties.X.value_rw_ds.fget.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1) -> int :'
|
||||
|
||||
>>> properties.X.value_rw_ds.fset.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1, (int)arg2) -> None :'
|
||||
|
||||
>>> properties.X.value_rw_ds.fget.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1) -> int :'
|
||||
|
||||
>>> properties.X.value_direct.fset.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1, (int)arg2) -> None :'
|
||||
|
||||
>>> properties.X.value_direct.fget.__doc__.strip().split("\\n")[0]
|
||||
'None( (properties_ext.X)arg1) -> int :'
|
||||
"""
|
||||
|
||||
# FIXME: cases to cover: pointer-to-member, preconstructed function
|
||||
|
||||
#import sys; sys.path.append(r'P:\Actimize4.0\smart_const\py_smart_const___Win32_Debug')
|
||||
import properties_ext as properties
|
||||
|
||||
|
||||
Reference in New Issue
Block a user