], None, None))
def test_square_brackets(self):
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: Tuple[int, str], no_really: str) -> List[str]'),
- ('foo', '', [
- ('a', 'typing.Tuple[int, str]', 'typing.Tuple[int, str]', None),
- ('no_really', 'str', 'str', None),
- ], 'typing.List[str]', 'typing.List[str]'))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: Tuple[int, str], no_really: str) -> List[str]',
+ # pybind11 2.12+
+ 'foo(a: tuple[int, str], no_really: str) -> list[str]'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [
+ ('a', 'tuple[int, str]', 'tuple[int, str]', None),
+ ('no_really', 'str', 'str', None),
+ ], 'list[str]', 'list[str]'))
def test_nested_square_brackets(self):
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: Tuple[int, List[Tuple[int, int]]], another: float) -> Union[str, None]'),
- ('foo', '', [
- ('a', 'typing.Tuple[int, typing.List[typing.Tuple[int, int]]]', 'typing.Tuple[int, typing.List[typing.Tuple[int, int]]]', None),
- ('another', 'float', 'float', None),
- ], 'typing.Union[str, None]', 'typing.Union[str, None]'))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: Tuple[int, Set[Tuple[int, int]]], another: float) -> Union[str, None]',
+ # pybind11 2.12+
+ 'foo(a: tuple[int, set[tuple[int, int]]], another: float) -> Union[str, None]'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [
+ ('a', 'tuple[int, set[tuple[int, int]]]', 'tuple[int, set[tuple[int, int]]]', None),
+ ('another', 'float', 'float', None),
+ ], 'typing.Union[str, None]', 'typing.Union[str, None]'))
def test_callable(self):
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: Callable[[int, Tuple[int, int]], float], another: float)'),
- ('foo', '', [
- ('a', 'typing.Callable[[int, typing.Tuple[int, int]], float]', 'typing.Callable[[int, typing.Tuple[int, int]], float]', None),
- ('another', 'float', 'float', None),
- ], None, None))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: Callable[[int, Dict[int, int]], float], another: float)',
+ # pybind11 2.12+
+ 'foo(a: Callable[[int, dict[int, int]], float], another: float)'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [
+ ('a', 'typing.Callable[[int, dict[int, int]], float]', 'typing.Callable[[int, dict[int, int]], float]', None),
+ ('another', 'float', 'float', None),
+ ], None, None))
def test_kwargs(self):
self.assertEqual(parse_pybind_signature(self.state, [],
('b', None, None, '3'),
], 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))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: Tuple[int, ...] = (1,("hello", \'world\'),3,4))',
+ # pybind11 2.12+
+ 'foo(a: tuple[int, ...] = (1,("hello", \'world\'),3,4))',
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [
+ ('a', 'tuple[int, ...]', '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])'),
def test_bad_return_type(self):
bad_signature = ('foo', '', [('…', None, None, None)], None, None)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo() -> List[[]'), bad_signature)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo() -> List]'), bad_signature)
- self.assertEqual(parse_pybind_signature(self.state, [], 'foo() -> ::std::vector<int>'), bad_signature)
+ for i in [
+ # pybind11 2.11 and older
+ 'foo() -> List[[]',
+ 'foo() -> List]',
+ # pybind11 2.12+
+ 'foo() -> list[[]',
+ 'foo() -> list]',
+ # C++ leaked into the signature
+ 'foo() -> ::std::vector<int>'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ bad_signature)
def test_crazy_stuff(self):
self.assertEqual(parse_pybind_signature(self.state, [],
('foo', '', [('…', None, None, None)], None, None))
def test_crazy_stuff_nested(self):
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: int, b: List[Math::Vector<4, UnsignedInt>])'),
- ('foo', '', [('…', None, None, None)], None, None))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: int, b: List[Math::Vector<4, UnsignedInt>])',
+ # pybind11 2.12+
+ 'foo(a: int, b: list[Math::Vector<4, UnsignedInt>])'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [('…', None, None, None)], None, None))
def test_crazy_stuff_docs(self):
self.assertEqual(parse_pybind_signature(self.state, [],
('foo', '', [('…', None, None, None)], None, None))
def test_crazy_return_nested(self):
- self.assertEqual(parse_pybind_signature(self.state, [],
- 'foo(a: int) -> List[Math::Vector<4, UnsignedInt>]'),
- ('foo', '', [('…', None, None, None)], None, None))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: int) -> List[Math::Vector<4, UnsignedInt>]',
+ # pybind11 2.12+
+ 'foo(a: int) -> list[Math::Vector<4, UnsignedInt>]'
+ ]:
+ self.assertEqual(parse_pybind_signature(self.state, [], i),
+ ('foo', '', [('…', None, None, None)], None, None))
def test_crazy_return_docs(self):
self.assertEqual(parse_pybind_signature(self.state, [],
state = copy.deepcopy(self.state)
state.name_mapping['module._module'] = 'module'
- self.assertEqual(parse_pybind_signature(state, [],
- 'foo(a: module._module.Foo, b: typing.Tuple[int, module._module.Bar]) -> module._module.Baz'),
- ('foo', '', [('a', 'module.Foo', 'module.Foo', None),
- ('b', 'typing.Tuple[int, module.Bar]', 'typing.Tuple[int, module.Bar]', None)], 'module.Baz', 'module.Baz'))
+ for i in [
+ # pybind11 2.11 and older
+ 'foo(a: module._module.Foo, b: Tuple[int, module._module.Bar]) -> module._module.Baz',
+ # pybind11 2.12+
+ 'foo(a: module._module.Foo, b: tuple[int, module._module.Bar]) -> module._module.Baz'
+ ]:
+ self.assertEqual(parse_pybind_signature(state, [], i),
+ ('foo', '', [
+ ('a', 'module.Foo', 'module.Foo', None),
+ ('b', 'tuple[int, module.Bar]', 'tuple[int, module.Bar]', None)
+ ], 'module.Baz', 'module.Baz'))
class Signatures(BaseInspectTestCase):
def test_positional_args(self):
- install-base:
extra: graphviz cmake ninja-build wget
- install-python-deps:
- # NumPy 2.0 doesn't work with pybind 2.11, see below
+ # NumPy 2.0 doesn't work with pybind < 2.12
numpy-version: ==1.26.4
# Ubuntu 22.04 has pygments 2.11
pygments-version: ==2.11.0
- test-plugins
- test-documentation-themes:
python-version: "3.10"
- # 2.12.0 is the first that works with NumPy 2.0, unfortunately it has
- # different docstring typing annotations to which I need to adapt tests
- # first. Pinning to a version before together with NumPy 1.
- pybind-version: "2.11.1"
+ # 2.9 series seems to be the first to work with Python 3.10
+ pybind-version: "2.9.2"
# 1.9.1 is in Ubuntu 22.04 repos, HOWEVER both 1.9.1 and 1.9.2 link
# against libclang-9.so.1, which is stupid. I think I even asked if the
# builds could be fixed back then, but of course they didn't even
- install-base:
extra: graphviz cmake ninja-build wget
- install-python-deps:
- # NumPy 2.0 doesn't work with pybind 2.11, see below
+ # NumPy 2.0 doesn't work with pybind < 2.12
numpy-version: ==1.26.4
# Ubuntu 24.04 has pygments 2.17
pygments-version: ==2.17.0
- test-plugins
- test-documentation-themes:
python-version: "3.11"
- # 2.12.0 is the first that works with NumPy 2.0, unfortunately it has
- # different docstring typing annotations to which I need to adapt tests
- # first. Pinning to a version before together with NumPy 1.
+ # 2.11.1 is the last that uses pre-PEP585 typing annotations, make sure
+ # it's explicitly tested
pybind-version: "2.11.1"
# 1.9.8 is in Ubuntu 24.04 repos
doxygen-version: "1.9.8"
steps:
- install-base:
extra: graphviz cmake ninja-build wget
- - install-python-deps:
- # NumPy 2.0 doesn't work with pybind 2.11, see below
- numpy-version: ==1.26.4
+ - install-python-deps
- checkout
- test-theme
- test-plugins
- test-documentation-themes:
python-version: "3.12"
- # 2.12.0 is the first that works with NumPy 2.0, unfortunately it has
- # different docstring typing annotations to which I need to adapt tests
- # first. Pinning to a version before together with NumPy 1.
- pybind-version: "2.11.1"
+ # 2.12 series is the first that uses PEP585 and first that works with
+ # NumPy 2.0
+ pybind-version: "2.12.1"
# 1.11 is the latest that passes all tests, 1.12 first needs
# https://github.com/doxygen/doxygen/pull/11141 merged to be usable.
doxygen-version: "1.11.0"