chiark / gitweb /
documentation/python: drop pybind11 2.2 support.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 4 Jan 2022 15:14:34 +0000 (16:14 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 4 Jan 2022 15:41:31 +0000 (16:41 +0100)
Version 2.3 is the oldest supported now. It got released in Oct 2019 and
there were a bunch of extra hacks needed for 2.2. Ubuntu 18.04 has 2.0.1
which isn't feasible to be supported either, but 20.04 already has 2.4,
so staying at 2.3 at a minimum is good enough I'd say.

documentation/python.py
documentation/test_python/test_pybind.py
package/ci/circleci.yml

index 8ae8347fe77ed259e8f1e11059f3542ff3fd2c27..d29ee660241ff32d9e0f32534e6efdf2508822ab 100755 (executable)
@@ -934,9 +934,7 @@ def parse_pybind_signature(state: State, referrer_path: List[str], signature: st
                 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:
@@ -1014,11 +1012,9 @@ def format_value(state: State, referrer_path: List[str], value) -> Optional[str]
     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__:
index e8dfe967a50816274d03005093f3742aced5789b..4570663e4c5f531df96adfb50b9bdb20b412052f 100644 (file)
@@ -127,53 +127,7 @@ class Signature(unittest.TestCase):
                 ('**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', '', [
@@ -182,7 +136,7 @@ class Signature(unittest.TestCase):
             ], 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'),
@@ -214,7 +168,7 @@ class Signature(unittest.TestCase):
     # 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)'),
index 9b3f86dee2fed84151f239c5086ca37f8705b48b..1ef9c62e18c0bcd9817a8efdaab44732222444d9 100644 (file)
@@ -196,9 +196,8 @@ jobs:
     - test-plugins
     - test-documentation-themes:
         python-version: "3.6"
-        # Again, deliberately using an old version to verify the old hacks
-        # still work for it
-        pybind-version: "2.2.4"
+        # We don't support anything before 2.3.0 anymore.
+        pybind-version: "2.3.0"
     - coverage
 
   py307: