chiark / gitweb /
documentation/python: gracefully handle also crazy return types.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 21 Apr 2019 20:55:40 +0000 (22:55 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Mon, 22 Apr 2019 15:53:36 +0000 (17:53 +0200)
documentation/python.py
documentation/test_python/test_pybind.py

index 33381b239bdb15b98a6da4dcc30ab19e7c7305de..772158be83fb7e13ce7b9f018462d31bdfda0609 100755 (executable)
@@ -245,7 +245,15 @@ def parse_pybind_signature(signature: str) -> Tuple[str, str, List[Tuple[str, st
     else:
         return_type = None
 
-    assert not signature or signature[0] == '\n'
+    if signature and signature[0] != '\n':
+        end = original_signature.find('\n')
+        logging.warning("cannot parse pybind11 function signature %s", original_signature[:end])
+        if end != -1 and len(original_signature) > end + 1 and original_signature[end + 1] == '\n':
+            brief = extract_brief(original_signature[end + 1:])
+        else:
+            brief = ''
+        return (name, brief, [('…', None, None)], None)
+
     if len(signature) > 1 and signature[1] == '\n':
         brief = extract_brief(signature[2:])
     else:
index 1547430f90b8c9df8f3ccdbd86333baef373f5fd..a03f91d4eba4d426e6ff94ba4068bf80318e406d 100644 (file)
@@ -116,6 +116,16 @@ class Signature(unittest.TestCase):
             'foo(a: int, b: Math::Vector<4, UnsignedInt>)\n\nThis is text!!'),
             ('foo', 'This is text!!', [('…', None, None)], None))
 
+    def test_crazy_return(self):
+        self.assertEqual(parse_pybind_signature(
+            'foo(a: int) -> Math::Vector<4, UnsignedInt>'),
+            ('foo', '', [('…', None, None)], None))
+
+    def test_crazy_return_docs(self):
+        self.assertEqual(parse_pybind_signature(
+            'foo(a: int) -> Math::Vector<4, UnsignedInt>\n\nThis returns!'),
+            ('foo', 'This returns!', [('…', None, None)], None))
+
     def test_no_name(self):
         self.assertEqual(parse_pybind_signature(
             '(arg0: MyClass) -> float'),