chiark / gitweb /
documentation/python: adapt to a minor change in pybind 2.3 signatures.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jul 2019 11:16:40 +0000 (13:16 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jul 2019 11:16:40 +0000 (13:16 +0200)
documentation/python.py
documentation/test_python/test_pybind.py

index 29121f32ab7801727bd83a6ab9c72a2ef04e33c2..74a5d185a9abea4a9f0caad43655107cd4b94318 100755 (executable)
@@ -242,8 +242,10 @@ def parse_pybind_signature(state: State, signature: str) -> Tuple[str, str, List
 
         # Default (optional) -- for now take everything until the next comma
         # TODO: ugh, do properly
-        if signature.startswith('='):
-            signature = signature[1:]
+        # The equals has spaces around since 2.3.0, preserve 2.2 compatibility.
+        # https://github.com/pybind/pybind11/commit/0826b3c10607c8d96e1d89dc819c33af3799a7b8
+        if signature.startswith(('=', ' = ')):
+            signature = signature[1 if signature[0] == '=' else 3:]
             default = _pybind_default_value_rx.match(signature).group(0)
             signature = signature[len(default):]
         else:
index fb29c0d820ee0837e55a1896bf7fcc167f82e72d..76a6d68974b70c81e22f79b18b4e74903d995b91 100644 (file)
@@ -98,7 +98,9 @@ class Signature(unittest.TestCase):
                 ('**kwargs', None, None),
             ], None))
 
-    def test_default_values(self):
+    # https://github.com/pybind/pybind11/commit/0826b3c10607c8d96e1d89dc819c33af3799a7b8,
+    # released in 2.3.0. We want to support both, so test both.
+    def test_default_values_pybind22(self):
         self.assertEqual(parse_pybind_signature(State({}),
             'foo(a: float=1.0, b: str=\'hello\')'),
             ('foo', '', [
@@ -106,6 +108,14 @@ class Signature(unittest.TestCase):
                 ('b', 'str', '\'hello\''),
             ], None))
 
+    def test_default_values_pybind23(self):
+        self.assertEqual(parse_pybind_signature(State({}),
+            'foo(a: float = 1.0, b: str = \'hello\')'),
+            ('foo', '', [
+                ('a', 'float', '1.0'),
+                ('b', 'str', '\'hello\''),
+            ], None))
+
     def test_crazy_stuff(self):
         self.assertEqual(parse_pybind_signature(State({}),
             'foo(a: int, b: Math::Vector<4, UnsignedInt>)'),