Much more efficient generation of function signatures, updated docs
This modification taps into some newer C++14 features (if present) to
generate function signatures considerably more efficiently at compile
time rather than at run time.
With this change, pybind11 binaries are now *2.1 times* smaller compared
to the Boost.Python baseline in the benchmark. Compilation times get a
nice improvement as well.
Visual Studio 2015 unfortunately doesn't implement 'constexpr' well
enough yet to support this change and uses a runtime fallback.
diff --git a/example/example11.cpp b/example/example11.cpp
index 522485c..9599f94 100644
--- a/example/example11.cpp
+++ b/example/example11.cpp
@@ -14,4 +14,5 @@
void init_ex11(py::module &m) {
m.def("kw_func", &kw_func, py::arg("x"), py::arg("y"));
m.def("kw_func2", &kw_func, py::arg("x") = 100, py::arg("y") = 200);
+ m.def("kw_func3", [](const char *) { }, py::arg("data") = std::string("Hello world!"));
}
diff --git a/example/example11.py b/example/example11.py
index 7fc1b48..7d0217a 100755
--- a/example/example11.py
+++ b/example/example11.py
@@ -1,19 +1,19 @@
#!/usr/bin/env python
from __future__ import print_function
-import sys, pydoc
+import sys
+import pydoc
+
sys.path.append('.')
-import example
-
-from example import kw_func
-from example import kw_func2
+from example import kw_func, kw_func2, kw_func3
print(pydoc.render_doc(kw_func, "Help on %s"))
print(pydoc.render_doc(kw_func2, "Help on %s"))
+print(pydoc.render_doc(kw_func3, "Help on %s"))
kw_func(5, 10)
-kw_func(5, y = 10)
-kw_func(y = 10, x = 5)
+kw_func(5, y=10)
+kw_func(y=10, x=5)
kw_func2()
@@ -24,3 +24,8 @@
kw_func2(5, 10)
kw_func2(x=5, y=10)
+
+try:
+ kw_func2(x=5, y=10, z=12)
+except Exception as e:
+ print("Caught expected exception: " + str(e))
diff --git a/example/example11.ref b/example/example11.ref
index 728e804..b7719b1 100644
--- a/example/example11.ref
+++ b/example/example11.ref
@@ -1,3 +1,18 @@
+Help on built-in function kw_func
+
+kkww__ffuunncc(...)
+ Signature : (x : int, y : int) -> None
+
+Help on built-in function kw_func2
+
+kkww__ffuunncc22(...)
+ Signature : (x : int = 100L, y : int = 200L) -> None
+
+Help on built-in function kw_func3
+
+kkww__ffuunncc33(...)
+ Signature : (data : str = u'Hello world!') -> None
+
kw_func(x=5, y=10)
kw_func(x=5, y=10)
kw_func(x=5, y=10)
@@ -7,13 +22,6 @@
kw_func(x=100, y=10)
kw_func(x=5, y=10)
kw_func(x=5, y=10)
-Help on built-in function kw_func
-
-kkww__ffuunncc(...) method of builtins.PyCapsule instance
- Signature : (x : int, y : int) -> None
-
-Help on built-in function kw_func2
-
-kkww__ffuunncc22(...) method of builtins.PyCapsule instance
- Signature : (x : int = 100, y : int = 200) -> None
+Caught expected exception: Incompatible function arguments. The following argument types are supported:
+ 1. (x : int = 100L, y : int = 200L) -> None