From: Vladimír Vondruš Date: Tue, 9 Jul 2019 11:16:40 +0000 (+0200) Subject: documentation/python: adapt to a minor change in pybind 2.3 signatures. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=e11df5d097948ef5c5ac2833152beeeb4c42b301;p=blog.git documentation/python: adapt to a minor change in pybind 2.3 signatures. --- diff --git a/documentation/python.py b/documentation/python.py index 29121f32..74a5d185 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -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: diff --git a/documentation/test_python/test_pybind.py b/documentation/test_python/test_pybind.py index fb29c0d8..76a6d689 100644 --- a/documentation/test_python/test_pybind.py +++ b/documentation/test_python/test_pybind.py @@ -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>)'),