mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 15:20:34 +00:00
Merge pull request #244 from JerryAtInnobec/master
Allow pybind11::arg to have 0, false, or "" as default values.
This commit is contained in:
commit
a62b3a07ba
@ -58,4 +58,5 @@ void init_ex11(py::module &m) {
|
|||||||
|
|
||||||
using namespace py::literals;
|
using namespace py::literals;
|
||||||
m.def("kw_func_udl", &kw_func, "x"_a, "y"_a=300);
|
m.def("kw_func_udl", &kw_func, "x"_a, "y"_a=300);
|
||||||
|
m.def("kw_func_udl_z", &kw_func, "x"_a, "y"_a=0);
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,14 @@ import pydoc
|
|||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from example import kw_func, kw_func2, kw_func3, kw_func4, call_kw_func
|
from example import kw_func, kw_func2, kw_func3, kw_func4, call_kw_func
|
||||||
from example import args_function, args_kwargs_function, kw_func_udl
|
from example import args_function, args_kwargs_function, kw_func_udl, kw_func_udl_z
|
||||||
|
|
||||||
print(pydoc.render_doc(kw_func, "Help on %s"))
|
print(pydoc.render_doc(kw_func, "Help on %s"))
|
||||||
print(pydoc.render_doc(kw_func2, "Help on %s"))
|
print(pydoc.render_doc(kw_func2, "Help on %s"))
|
||||||
print(pydoc.render_doc(kw_func3, "Help on %s"))
|
print(pydoc.render_doc(kw_func3, "Help on %s"))
|
||||||
print(pydoc.render_doc(kw_func4, "Help on %s"))
|
print(pydoc.render_doc(kw_func4, "Help on %s"))
|
||||||
print(pydoc.render_doc(kw_func_udl, "Help on %s"))
|
print(pydoc.render_doc(kw_func_udl, "Help on %s"))
|
||||||
|
print(pydoc.render_doc(kw_func_udl_z, "Help on %s"))
|
||||||
|
|
||||||
kw_func(5, 10)
|
kw_func(5, 10)
|
||||||
kw_func(5, y=10)
|
kw_func(5, y=10)
|
||||||
@ -42,3 +43,4 @@ args_function('arg1_value', 'arg2_value', 3)
|
|||||||
args_kwargs_function('arg1_value', 'arg2_value', arg3='arg3_value', arg4=4)
|
args_kwargs_function('arg1_value', 'arg2_value', arg3='arg3_value', arg4=4)
|
||||||
|
|
||||||
kw_func_udl(x=5, y=10)
|
kw_func_udl(x=5, y=10)
|
||||||
|
kw_func_udl_z(x=5)
|
||||||
|
@ -23,6 +23,11 @@ Help on built-in function kw_func_udl in module example
|
|||||||
kkww__ffuunncc__uuddll(...)
|
kkww__ffuunncc__uuddll(...)
|
||||||
kw_func_udl(x : int, y : int = 300L) -> NoneType
|
kw_func_udl(x : int, y : int = 300L) -> NoneType
|
||||||
|
|
||||||
|
Help on built-in function kw_func_udl_z in module example
|
||||||
|
|
||||||
|
kkww__ffuunncc__uuddll__zz(...)
|
||||||
|
kw_func_udl_z(x : int, y : int = 0L) -> NoneType
|
||||||
|
|
||||||
kw_func(x=5, y=10)
|
kw_func(x=5, y=10)
|
||||||
kw_func(x=5, y=10)
|
kw_func(x=5, y=10)
|
||||||
kw_func(x=5, y=10)
|
kw_func(x=5, y=10)
|
||||||
@ -47,3 +52,4 @@ got keyword argument: arg3 -> arg3_value
|
|||||||
got keyword argument: arg4 -> 4
|
got keyword argument: arg4 -> 4
|
||||||
|
|
||||||
kw_func(x=5, y=10)
|
kw_func(x=5, y=10)
|
||||||
|
kw_func(x=5, y=0)
|
||||||
|
@ -18,14 +18,14 @@ template <typename T> struct arg_t;
|
|||||||
|
|
||||||
/// Annotation for keyword arguments
|
/// Annotation for keyword arguments
|
||||||
struct arg {
|
struct arg {
|
||||||
constexpr arg(const char *name) : name(name) { }
|
constexpr explicit arg(const char *name) : name(name) { }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr arg_t<T> operator=(const T &value) const { return {name, value}; }
|
constexpr arg_t<T> operator=(const T &value) const { return {name, value}; }
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
constexpr arg_t<const T *> operator=(T const (&value)[N]) const {
|
constexpr arg_t<const T *> operator=(T const (&value)[N]) const {
|
||||||
return operator=((const T *) value);
|
return operator=((const T *) value);
|
||||||
};
|
}
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
@ -40,7 +40,7 @@ template <typename T> struct arg_t : public arg {
|
|||||||
|
|
||||||
inline namespace literals {
|
inline namespace literals {
|
||||||
/// String literal version of arg
|
/// String literal version of arg
|
||||||
constexpr arg operator"" _a(const char *name, size_t) { return {name}; }
|
constexpr arg operator"" _a(const char *name, size_t) { return arg(name); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Annotation for methods
|
/// Annotation for methods
|
||||||
|
Loading…
Reference in New Issue
Block a user