From 13b22bf4f6ff75c720dda5acba7b3ba9640807be Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Sun, 28 Feb 2016 21:23:39 -0500 Subject: [PATCH 1/3] Signature formatting for sphinx --- example/example11.ref | 10 +++++----- example/example5.ref | 2 +- include/pybind11/pybind11.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/example11.ref b/example/example11.ref index 8edc06580..4e04a3b7d 100644 --- a/example/example11.ref +++ b/example/example11.ref @@ -1,22 +1,22 @@ Help on built-in function kw_func in module example kkww__ffuunncc(...) - Signature : (x : int, y : int) -> NoneType + kw_func(x : int, y : int) Help on built-in function kw_func2 in module example kkww__ffuunncc22(...) - Signature : (x : int = 100L, y : int = 200L) -> NoneType + kw_func2(x : int = 100L, y : int = 200L) Help on built-in function kw_func3 in module example kkww__ffuunncc33(...) - Signature : (data : unicode = u'Hello world!') -> NoneType + kw_func3(data : unicode = u'Hello world!') Help on built-in function kw_func4 in module example kkww__ffuunncc44(...) - Signature : (myList : list = [13L, 17L]) -> NoneType + kw_func4(myList : list = [13L, 17L]) kw_func(x=5, y=10) kw_func(x=5, y=10) @@ -28,7 +28,7 @@ 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) kw_func4: 13 17 kw_func4: 1 2 3 diff --git a/example/example5.ref b/example/example5.ref index d1da88311..40a355c53 100644 --- a/example/example5.ref +++ b/example/example5.ref @@ -13,7 +13,7 @@ Rabbit is a parrot Polly is a parrot Molly is a dog The following error is expected: Incompatible function arguments. The following argument types are supported: - 1. (example.Dog) -> NoneType + 1. (example.Dog) Callback function 1 called! False diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 4cf8ead1f..5153c46f2 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -81,7 +81,7 @@ public: /* Generate a readable signature describing the function's arguments and return value types */ using detail::descr; - PYBIND11_DESCR signature = cast_in::name() + detail::_(" -> ") + cast_out::name(); + PYBIND11_DESCR signature = cast_in::name(); /* Register the function with Python from generic (non-templated) code */ initialize(rec, signature.text(), signature.types(), sizeof...(Args)); @@ -157,7 +157,7 @@ protected: /* Generate a readable signature describing the function's arguments and return value types */ using detail::descr; - PYBIND11_DESCR signature = cast_in::name() + detail::_(" -> ") + cast_out::name(); + PYBIND11_DESCR signature = cast_in::name(); /* Register the function with Python from generic (non-templated) code */ initialize(rec, signature.text(), signature.types(), sizeof...(Args)); @@ -298,7 +298,7 @@ protected: for (auto it = chain_start; it != nullptr; it = it->next) { if (chain) signatures += std::to_string(++index) + ". "; - signatures += "Signature : "; + signatures += rec->name; signatures += it->signature; signatures += "\n"; if (it->doc && strlen(it->doc) > 0) { From 0e04fdf3f6a586936518052c97c0e5136f70aa45 Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Tue, 8 Mar 2016 16:42:12 -0500 Subject: [PATCH 2/3] Add generic signature for overloads --- include/pybind11/pybind11.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 5153c46f2..43cc02c3a 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -295,6 +295,13 @@ protected: int index = 0; /* Create a nice pydoc rec including all signatures and docstrings of the functions in the overload chain */ + if (chain) { + // First a generic signature + signatures += rec->name; + signatures += "(*args, **kwargs)\n"; + signatures += "Overloaded function.\n\n"; + } + // Then specific overload signatures for (auto it = chain_start; it != nullptr; it = it->next) { if (chain) signatures += std::to_string(++index) + ". "; From 4c7bf9bb947c748c75d7ab2ce58624dacc8b32dd Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Tue, 8 Mar 2016 18:44:04 -0500 Subject: [PATCH 3/3] Add return type --- example/example11.ref | 10 +++++----- example/example5.ref | 2 +- include/pybind11/pybind11.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/example11.ref b/example/example11.ref index 4e04a3b7d..54e4fef31 100644 --- a/example/example11.ref +++ b/example/example11.ref @@ -1,22 +1,22 @@ Help on built-in function kw_func in module example kkww__ffuunncc(...) - kw_func(x : int, y : int) + kw_func(x : int, y : int) -> NoneType Help on built-in function kw_func2 in module example kkww__ffuunncc22(...) - kw_func2(x : int = 100L, y : int = 200L) + kw_func2(x : int = 100L, y : int = 200L) -> NoneType Help on built-in function kw_func3 in module example kkww__ffuunncc33(...) - kw_func3(data : unicode = u'Hello world!') + kw_func3(data : unicode = u'Hello world!') -> NoneType Help on built-in function kw_func4 in module example kkww__ffuunncc44(...) - kw_func4(myList : list = [13L, 17L]) + kw_func4(myList : list = [13L, 17L]) -> NoneType kw_func(x=5, y=10) kw_func(x=5, y=10) @@ -28,7 +28,7 @@ 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) + 1. (x : int = 100L, y : int = 200L) -> NoneType kw_func4: 13 17 kw_func4: 1 2 3 diff --git a/example/example5.ref b/example/example5.ref index 40a355c53..d1da88311 100644 --- a/example/example5.ref +++ b/example/example5.ref @@ -13,7 +13,7 @@ Rabbit is a parrot Polly is a parrot Molly is a dog The following error is expected: Incompatible function arguments. The following argument types are supported: - 1. (example.Dog) + 1. (example.Dog) -> NoneType Callback function 1 called! False diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 43cc02c3a..a9d5a1236 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -81,7 +81,7 @@ public: /* Generate a readable signature describing the function's arguments and return value types */ using detail::descr; - PYBIND11_DESCR signature = cast_in::name(); + PYBIND11_DESCR signature = cast_in::name() + detail::_(" -> ") + cast_out::name(); /* Register the function with Python from generic (non-templated) code */ initialize(rec, signature.text(), signature.types(), sizeof...(Args)); @@ -157,7 +157,7 @@ protected: /* Generate a readable signature describing the function's arguments and return value types */ using detail::descr; - PYBIND11_DESCR signature = cast_in::name(); + PYBIND11_DESCR signature = cast_in::name() + detail::_(" -> ") + cast_out::name(); /* Register the function with Python from generic (non-templated) code */ initialize(rec, signature.text(), signature.types(), sizeof...(Args));