Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into implicit-cpp-conv…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
jagerman committed Aug 5, 2016
2 parents 7b8fab4 + 5289af5 commit 29d04e4
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 71 deletions.
6 changes: 6 additions & 0 deletions example/eigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ def check_got_vs_ref(got_x, ref_x):

print("symmetric_lower %s" % ("OK" if (symmetric_lower(asymm) == symm_lower).all() else "FAILED"))
print("symmetric_upper %s" % ("OK" if (symmetric_upper(asymm) == symm_upper).all() else "FAILED"))

print(double_col.__doc__)
print(double_row.__doc__)
print(double_mat_rm.__doc__)
print(sparse_passthrough_r.__doc__)
print(sparse_passthrough_c.__doc__)
5 changes: 5 additions & 0 deletions example/eigen.ref
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ block(1,4,3,2) OK
incr_diag OK
symmetric_lower OK
symmetric_upper OK
double_col(arg0: numpy.ndarray[float32[m, 1]]) -> numpy.ndarray[float32[m, 1]]
double_row(arg0: numpy.ndarray[float32[1, n]]) -> numpy.ndarray[float32[1, n]]
double_mat_rm(arg0: numpy.ndarray[float32[m, n]]) -> numpy.ndarray[float32[m, n]]
sparse_passthrough_r(arg0: scipy.sparse.csr_matrix[float32]) -> scipy.sparse.csr_matrix[float32]
sparse_passthrough_c(arg0: scipy.sparse.csc_matrix[float32]) -> scipy.sparse.csc_matrix[float32]
11 changes: 10 additions & 1 deletion example/example-arg-keywords-and-defaults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ void args_kwargs_function(py::args args, py::kwargs kwargs) {
}
}

struct KWClass {
void foo(int, float) {}
};

void init_ex_arg_keywords_and_defaults(py::module &m) {
m.def("kw_func", &kw_func, py::arg("x"), py::arg("y"));
m.def("kw_func0", &kw_func);
m.def("kw_func1", &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!"));

Expand All @@ -59,4 +64,8 @@ void init_ex_arg_keywords_and_defaults(py::module &m) {
using namespace py::literals;
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);

py::class_<KWClass>(m, "KWClass")
.def("foo0", &KWClass::foo)
.def("foo1", &KWClass::foo, "x"_a, "y"_a);
}
17 changes: 12 additions & 5 deletions example/example-arg-keywords-and-defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@

sys.path.append('.')

from example import kw_func, kw_func2, kw_func3, kw_func4, call_kw_func
from example import kw_func0, kw_func1, kw_func2, kw_func3, kw_func4, call_kw_func
from example import args_function, args_kwargs_function, kw_func_udl, kw_func_udl_z
from example import KWClass

print(pydoc.render_doc(kw_func, "Help on %s"))
print(pydoc.render_doc(kw_func0, "Help on %s"))
print(pydoc.render_doc(kw_func1, "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_func4, "Help on %s"))
print(pydoc.render_doc(kw_func_udl, "Help on %s"))
print(pydoc.render_doc(kw_func_udl_z, "Help on %s"))
print(pydoc.render_doc(args_function, "Help on %s"))
print(pydoc.render_doc(args_kwargs_function, "Help on %s"))

kw_func(5, 10)
kw_func(5, y=10)
kw_func(y=10, x=5)
print(KWClass.foo0.__doc__)
print(KWClass.foo1.__doc__)

kw_func1(5, 10)
kw_func1(5, y=10)
kw_func1(y=10, x=5)

kw_func2()

Expand Down
42 changes: 31 additions & 11 deletions example/example-arg-keywords-and-defaults.ref
Original file line number Diff line number Diff line change
@@ -1,32 +1,52 @@
Help on built-in function kw_func in module example
Help on built-in function kw_func0 in module example

kkww__ffuunncc(...)
kw_func(x : int, y : int) -> NoneType
kkww__ffuunncc00(...)
kw_func0(arg0: int, arg1: int) -> None

Help on built-in function kw_func1 in module example

kkww__ffuunncc11(...)
kw_func1(x: int, y: int) -> None

Help on built-in function kw_func2 in module example

kkww__ffuunncc22(...)
kw_func2(x : int = 100L, y : int = 200L) -> NoneType
kw_func2(x: int=100L, y: int=200L) -> None

Help on built-in function kw_func3 in module example

kkww__ffuunncc33(...)
kw_func3(data : unicode = u'Hello world!') -> NoneType
kw_func3(data: unicode=u'Hello world!') -> None

Help on built-in function kw_func4 in module example

kkww__ffuunncc44(...)
kw_func4(myList : list<int> = [13L, 17L]) -> NoneType
kw_func4(myList: List[int]=[13L, 17L]) -> None

Help on built-in function kw_func_udl in module example

kkww__ffuunncc__uuddll(...)
kw_func_udl(x : int, y : int = 300L) -> NoneType
kw_func_udl(x: int, y: int=300L) -> None

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_udl_z(x: int, y: int=0L) -> None

Help on built-in function args_function in module example

aarrggss__ffuunnccttiioonn(...)
args_function(*args) -> None

Help on built-in function args_kwargs_function in module example

aarrggss__kkwwaarrggss__ffuunnccttiioonn(...)
args_kwargs_function(*args, **kwargs) -> None


foo0(self: KWClass, arg0: int, arg1: float) -> None
foo1(self: KWClass, x: int, y: float) -> None


kw_func(x=5, y=10)
kw_func(x=5, y=10)
Expand All @@ -38,10 +58,10 @@ kw_func(x=100, y=10)
kw_func(x=5, y=10)
kw_func(x=5, y=10)
Caught expected exception: Incompatible function arguments. The following argument types are supported:
1. (x : int = 100L, y : int = 200L) -> NoneType
1. (x: int=100L, y: int=200L) -> None
Invoked with:
kw_func4: 13 17
kw_func4: 1 2 3
kw_func4: 13 17
kw_func4: 1 2 3
kw_func(x=1234, y=5678)
got argument: arg1_value
got argument: arg2_value
Expand Down
3 changes: 3 additions & 0 deletions example/example-callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ def func3(a):
print("All OK!")
else:
print("Problem!")

print(test_callback3.__doc__)
print(test_callback4.__doc__)
5 changes: 4 additions & 1 deletion example/example-callbacks.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Molly is a dog
Molly is a dog
Woof!
The following error is expected: Incompatible function arguments. The following argument types are supported:
1. (example.Dog) -> NoneType
1. (arg0: example.Dog) -> None
Invoked with: <example.Pet object at 0>
Callback function 1 called!
False
Expand Down Expand Up @@ -36,3 +36,6 @@ could not convert to a function pointer.
All OK!
could not convert to a function pointer.
All OK!

test_callback3(arg0: Callable[[int], int]) -> None
test_callback4() -> Callable[[int], int]
2 changes: 2 additions & 0 deletions example/example-numpy-vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@
selective_func(np.array([1], dtype=np.int32))
selective_func(np.array([1.0], dtype=np.float32))
selective_func(np.array([1.0j], dtype=np.complex64))

print(vectorized_func.__doc__)
1 change: 1 addition & 0 deletions example/example-numpy-vectorize.ref
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ my_func(x:int=6, y:float=3, z:float=2)
Int branch taken.
Float branch taken.
Complex float branch taken.
vectorized_func(arg0: numpy.ndarray[int], arg1: numpy.ndarray[float], arg2: numpy.ndarray[float]) -> object
2 changes: 1 addition & 1 deletion example/example-opaque-types.ref
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Called ExampleMandA default constructor..
Got void ptr : 0x7f9ba0f3c430
Called ExampleMandA destructor (0)
Caught expected exception: Incompatible function arguments. The following argument types are supported:
1. (capsule) -> NoneType
1. (arg0: capsule) -> None
Invoked with: [1, 2, 3]
None
Got null str : 0x0
Expand Down
26 changes: 13 additions & 13 deletions example/example-python-types.ref
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class EExxaammpplleePPyytthhoonnTTyyppeess(__builtin__.object)
| x.__init__(...) initializes x; see help(type(x)) for signature
|
| ggeett__aarrrraayy(...)
| Signature : (example.ExamplePythonTypes) -> list<unicode>[2]
|
| Signature : (example.ExamplePythonTypes) -> List[unicode[2]]
| Return a C++ array
|
| ggeett__ddiicctt(...)
Expand All @@ -44,8 +44,8 @@ class EExxaammpplleePPyytthhoonnTTyyppeess(__builtin__.object)
| Return a Python dictionary
|
| ggeett__ddiicctt__22(...)
| Signature : (example.ExamplePythonTypes) -> dict<unicode, unicode>
|
| Signature : (example.ExamplePythonTypes) -> Dict[unicode, unicode]
| Return a C++ dictionary
|
| ggeett__lliisstt(...)
Expand All @@ -54,8 +54,8 @@ class EExxaammpplleePPyytthhoonnTTyyppeess(__builtin__.object)
| Return a Python list
|
| ggeett__lliisstt__22(...)
| Signature : (example.ExamplePythonTypes) -> list<unicode>
|
| Signature : (example.ExamplePythonTypes) -> List[unicode]
| Return a C++ list
|
| ggeett__sseett(...)
Expand All @@ -69,53 +69,53 @@ class EExxaammpplleePPyytthhoonnTTyyppeess(__builtin__.object)
| Return a C++ set
|
| ppaaiirr__ppaasssstthhrroouugghh(...)
| Signature : (example.ExamplePythonTypes, (bool, unicode)) -> (unicode, bool)
|
| Signature : (example.ExamplePythonTypes, Tuple[bool, unicode]) -> Tuple[unicode, bool]
| Return a pair in reversed order
|
| pprriinntt__aarrrraayy(...)
| Signature : (example.ExamplePythonTypes, list<unicode>[2]) -> NoneType
|
| Signature : (example.ExamplePythonTypes, List[unicode[2]]) -> None
| Print entries of a C++ array
|
| pprriinntt__ddiicctt(...)
| Signature : (example.ExamplePythonTypes, dict) -> NoneType
|
| Signature : (example.ExamplePythonTypes, dict) -> None
| Print entries of a Python dictionary
|
| pprriinntt__ddiicctt__22(...)
| Signature : (example.ExamplePythonTypes, dict<unicode, unicode>) -> NoneType
|
| Signature : (example.ExamplePythonTypes, Dict[unicode, unicode]) -> None
| Print entries of a C++ dictionary
|
| pprriinntt__lliisstt(...)
| Signature : (example.ExamplePythonTypes, list) -> NoneType
|
| Signature : (example.ExamplePythonTypes, list) -> None
| Print entries of a Python list
|
| pprriinntt__lliisstt__22(...)
| Signature : (example.ExamplePythonTypes, list<unicode>) -> NoneType
|
| Signature : (example.ExamplePythonTypes, List[unicode]) -> None
| Print entries of a C++ list
|
| pprriinntt__sseett(...)
| Signature : (example.ExamplePythonTypes, set) -> NoneType
|
| Signature : (example.ExamplePythonTypes, set) -> None
| Print entries of a Python set
|
| pprriinntt__sseett__22(...)
| Signature : (example.ExamplePythonTypes, set<unicode>) -> NoneType
|
| Signature : (example.ExamplePythonTypes, Set[unicode]) -> None
| Print entries of a C++ set
|
| tthhrrooww__eexxcceeppttiioonn(...)
| Signature : (example.ExamplePythonTypes) -> NoneType
|
| Signature : (example.ExamplePythonTypes) -> None
| Throw an exception
|
| ttuuppllee__ppaasssstthhrroouugghh(...)
| Signature : (example.ExamplePythonTypes, (bool, unicode, int)) -> (int, unicode, bool)
|
| Signature : (example.ExamplePythonTypes, Tuple[bool, unicode, int]) -> Tuple[int, unicode, bool]
| Return a triple in reversed order
|
| ----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions example/issues.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Yay..
[3, 5, 7, 9, 11, 13, 15]
0==0, 1==1, 2==2, 3==3, 4==4, 5==5, 6==6, 7==7, 8==8, 9==9,
Failed as expected: Incompatible function arguments. The following argument types are supported:
1. (example.issues.ElementA) -> NoneType
1. (arg0: example.issues.ElementA) -> None
Invoked with: None
Failed as expected: Incompatible function arguments. The following argument types are supported:
1. (int) -> int
1. (arg0: int) -> int
Invoked with: 5.2
12.0
C++ version
Expand All @@ -21,6 +21,6 @@ In python f()
StrIssue.__str__ called
StrIssue[3]
Failed as expected: Incompatible constructor arguments. The following argument types are supported:
1. example.issues.StrIssue(int)
1. example.issues.StrIssue(arg0: int)
2. example.issues.StrIssue()
Invoked with: no, such, constructor
23 changes: 13 additions & 10 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ template <> class type_caster<void_type> {
static handle cast(void_type, return_value_policy /* policy */, handle /* parent */) {
return handle(Py_None).inc_ref();
}
PYBIND11_TYPE_CASTER(void_type, _("NoneType"));
PYBIND11_TYPE_CASTER(void_type, _("None"));
};

template <> class type_caster<void> : public type_caster<void_type> {
Expand Down Expand Up @@ -535,7 +535,7 @@ template <> class type_caster<void> : public type_caster<void_type> {

template <typename T> using cast_op_type = void*&;
operator void *&() { return value; }
static PYBIND11_DESCR name() { return _("capsule"); }
static PYBIND11_DESCR name() { return type_descr(_("capsule")); }
private:
void *value = nullptr;
};
Expand Down Expand Up @@ -710,8 +710,8 @@ template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> {

static PYBIND11_DESCR name() {
return type_descr(
_("(") + type_caster<typename intrinsic_type<T1>::type>::name() +
_(", ") + type_caster<typename intrinsic_type<T2>::type>::name() + _(")"));
_("Tuple[") + type_caster<typename intrinsic_type<T1>::type>::name() +
_(", ") + type_caster<typename intrinsic_type<T2>::type>::name() + _("]"));
}

template <typename T> using cast_op_type = type;
Expand Down Expand Up @@ -749,12 +749,6 @@ template <typename... Tuple> class type_caster<std::tuple<Tuple...>> {
static handle cast(const type &src, return_value_policy policy, handle parent) {
return cast(src, policy, parent, typename make_index_sequence<size>::type());
}
static PYBIND11_DESCR name() {
return type_descr(
_("(") +
detail::concat(_(PYBIND11_DESCR_ARG_PREFIX) + type_caster<typename intrinsic_type<Tuple>::type>::name()...) +
_(")"));
}
template <typename T> using cast_op_type = type;
operator type() {
return cast(typename make_index_sequence<size>::type());
Expand All @@ -779,6 +773,15 @@ template <typename... Tuple> class type_caster<std::tuple<Tuple...>> {
fvars->loaded[1] = true;
}

static PYBIND11_DESCR element_names() {
return detail::concat(_(PYBIND11_DESCR_ARG_PREFIX) + type_caster<typename intrinsic_type<Tuple>::type>::name()...);
}

static PYBIND11_DESCR name() {
return type_descr(
_("Tuple[") + element_names() + _("]"));
}

template <typename ReturnValue, typename Func> typename std::enable_if<!std::is_void<ReturnValue>::value, ReturnValue>::type call(Func &&f) {
return call<ReturnValue>(std::forward<Func>(f), typename make_index_sequence<size>::type());
}
Expand Down

0 comments on commit 29d04e4

Please sign in to comment.