# Expecting end of the signature line now, if not there, we failed
if signature and signature[0] != '\n': raise SyntaxError("Expected end of the signature, got `{}`".format(signature))
- # Failed to parse, return an ellipsis and docs
+ # Failed to parse, return with a single parameter with name being None and
+ # docs
except SyntaxError as e:
end = original_signature.find('\n')
logging.warning("cannot parse pybind11 function signature %s: %s", (original_signature[:end if end != -1 else None]), e)
docstring = inspect.cleandoc(original_signature[end + 1:])
else:
docstring = ''
- return (name, docstring, [('…', None, None, None, None)], None, None, None)
+ return (name, docstring, [(None, None, None, None, None)], None, None, None)
if len(signature) > 1 and signature[1] == '\n':
docstring = inspect.cleandoc(signature[2:])
# https://docs.python.org/3/library/inspect.html#inspect.signature
except ValueError:
param = Empty()
- param.name = '...'
+ param.name = None
param.type, param.type_relative, param.type_link = None, None, None
param.default, param.default_relative, param.default_link = None, None, None
out.params = [param]
# Common path for parameter / exception / return value docs and search
path_str = '.'.join(entry.path)
for out in overloads:
- signature = '({})'.format(', '.join(['{}: {}'.format(param.name, param.type) if param.type else param.name for param in out.params]))
+ # In case of introspection error, there's just a single param with name
+ # and everything else being None, replace it with ... to match what the
+ # HTML output shows
+ signature = '({})'.format(', '.join(['{}: {}'.format(param.name, param.type) if param.type else param.name or '...' for param in out.params]))
param_names = [param.name for param in out.params]
# Call all scope enter hooks for this particular overload
('a', 'str', 'str', 'str', '[dict(key="A", value=\'B\')["key"][0], None][0]')
], None, None, None))
- bad_signature = ('foo', '', [('…', None, None, None, None)], None, None, None)
+ bad_signature = ('foo', '', [(None, None, None, None, None)], None, None, None)
self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float = [0][)'), bad_signature)
self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float = ()'), bad_signature)
], None, None, None))
# This will fail
- bad_signature = ('foo', '', [('…', None, None, None, None)], None, None, None)
+ bad_signature = ('foo', '', [(None, None, None, None, None)], None, None, None)
self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: Enum = <Enum.CHARACTERS_AFTER: 17>a)'), bad_signature)
self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: Enum = <Enum.CHARACTERS_AFTER: 89><)'), bad_signature)
def test_bad_return_type(self):
- bad_signature = ('foo', '', [('…', None, None, None, None)], None, None, None)
+ bad_signature = ('foo', '', [(None, None, None, None, None)], None, None, None)
for i in [
# pybind11 2.11 and older
'foo() -> List[[]',
def test_crazy_stuff(self):
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: int, b: Math::Vector<4, UnsignedInt>)'),
- ('foo', '', [('…', None, None, None, None)], None, None, None))
+ ('foo', '', [(None, None, None, None, None)], None, None, None))
def test_crazy_stuff_nested(self):
for i in [
'foo(a: int, b: list[Math::Vector<4, UnsignedInt>])'
]:
self.assertEqual(parse_pybind_signature(self.state, [], i),
- ('foo', '', [('…', None, None, None, None)], None, None, None))
+ ('foo', '', [(None, None, None, None, None)], None, None, None))
def test_crazy_stuff_docs(self):
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: int, b: Math::Vector<4, UnsignedInt>)\n\nThis is text!!'),
- ('foo', 'This is text!!', [('…', None, None, None, None)], None, None, None))
+ ('foo', 'This is text!!', [(None, None, None, None, None)], None, None, None))
def test_crazy_return(self):
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: int) -> Math::Vector<4, UnsignedInt>'),
- ('foo', '', [('…', None, None, None, None)], None, None, None))
+ ('foo', '', [(None, None, None, None, None)], None, None, None))
def test_crazy_return_nested(self):
for i in [
'foo(a: int) -> list[Math::Vector<4, UnsignedInt>]'
]:
self.assertEqual(parse_pybind_signature(self.state, [], i),
- ('foo', '', [('…', None, None, None, None)], None, None, None))
+ ('foo', '', [(None, None, None, None, None)], None, None, None))
def test_crazy_return_docs(self):
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: int) -> Math::Vector<4, UnsignedInt>\n\nThis returns!'),
- ('foo', 'This returns!', [('…', None, None, None, None)], None, None, None))
+ ('foo', 'This returns!', [(None, None, None, None, None)], None, None, None))
def test_no_name(self):
self.assertEqual(parse_pybind_signature(self.state, [],