arg_type_link = None
# Default (optional)
- # The equals has spaces around since 2.3.0, preserve 2.2 compatibility.
- # https://github.com/pybind/pybind11/commit/0826b3c10607c8d96e1d89dc819c33af3799a7b8
- if signature.startswith(('=', ' = ')):
+ if signature.startswith(' = '):
signature = signature[1 if signature[0] == '=' else 3:]
signature, default = _pybind11_extract_default_argument(signature)
else:
if value is None: return str(value)
if isinstance(value, enum.Enum):
return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name))
- # pybind enums have the __members__ attribute instead. Since 2.3 pybind11
- # has .name like enum.Enum, but we still need to support 2.2 so hammer it
- # out of a str() instead.
+ # pybind enums have the __members__ attribute instead
elif state.config['PYBIND11_COMPATIBILITY'] and hasattr(value.__class__, '__members__'):
- return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, str(value).partition('.')[2]))
+ return make_name_link(state, referrer_path, '{}.{}.{}'.format(value.__class__.__module__, value.__class__.__qualname__, value.name))
elif inspect.isfunction(value):
return html.escape('<function {}>'.format(value.__name__))
elif '__repr__' in type(value).__dict__:
('**kwargs', None, None, None),
], None, None))
- # 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(self.state, [],
- 'foo(a: float=1.0, b: str=\'hello\')'),
- ('foo', '', [
- ('a', 'float', 'float', '1.0'),
- ('b', 'str', 'str', '\'hello\''),
- ], None, None))
-
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: float=libA.foo(libB.goo(123), libB.bar + 13) + 2, b=3)'),
- ('foo', '', [
- ('a', 'float', 'float', 'libA.foo(libB.goo(123), libB.bar + 13) + 2'),
- ('b', None, None, '3'),
- ], None, None))
-
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: List=[1, 2, 3], b: Tuple=(1, 2, 3, "str"))'),
- ('foo', '', [
- ('a', 'typing.List', 'typing.List', '[1, 2, 3]'),
- ('b', "typing.Tuple", "typing.Tuple", '(1, 2, 3, "str")'),
- ], None, None))
-
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: Tuple[int, ...]=(1,("hello", \'world\'),3,4))'),
- ('foo', '', [
- ('a', 'typing.Tuple[int, ...]',
- 'typing.Tuple[int, ...]',
- '(1,("hello", \'world\'),3,4)')
- ], None, None))
-
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: str=[dict(key="A", value=\'B\')["key"][0], None][0])'),
- ('foo', '', [
- ('a', 'str', 'str', '[dict(key="A", value=\'B\')["key"][0], None][0]')
- ], None, None))
-
- bad_signature = ('foo', '', [('…', 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)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=(()'), bad_signature)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=))'), bad_signature)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo(a: float=])'), bad_signature)
-
- def test_default_values_pybind23(self):
+ def test_default_values(self):
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: float = 1.0, b: str = \'hello\')'),
('foo', '', [
], None, None))
self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: float = libA.foo(libB.goo(123), libB.bar + 13) + 2, b=3)'),
+ 'foo(a: float = libA.foo(libB.goo(123), libB.bar + 13) + 2, b = 3)'),
('foo', '', [
('a', 'float', 'float', 'libA.foo(libB.goo(123), libB.bar + 13) + 2'),
('b', None, None, '3'),
# annoying but what can I do. Want to support both this and the original
# behavior in case they revert the insanity again, so test that both
# variants give the same output.
- def test_default_values_pybind26(self):
+ def test_default_enum_values_pybind26(self):
# Before the insane change
self.assertEqual(parse_pybind_signature(self.state, [],
'foo(a: bar.Enum = Enum.FOO_BAR)'),