@@ -8,6 +8,83 @@ to a new version. But it goes into more detail. This includes things like
8
8
deprecated APIs and their replacements, build system changes, general code
9
9
modernization and other useful information.
10
10
11
+ .. _upgrade-guide-3.0 :
12
+
13
+ v3.0
14
+ ====
15
+
16
+ pybind11 v3.0 introduces major new features, but the vast majority of
17
+ existing extensions are expected to build and run without modification. Minor
18
+ adjustments may be needed in rare cases, and any such changes can be easily
19
+ wrapped in preprocessor conditionals to maintain compatibility with the
20
+ 2.x series.
21
+
22
+ However, due to new features and modernizations, extensions built with
23
+ pybind11 v3.0 are not ABI-compatible with those built using v2.12. To ensure
24
+ cross-extension-module compatibility, it is recommended to rebuild all
25
+ pybind11-based extensions with v3.0.
26
+
27
+ A major new feature in this release is the integration of
28
+ ``py::smart_holder ``, which improves support for ``std::unique_ptr ``
29
+ and ``std::shared_ptr ``, resolving several long-standing issues. See
30
+ :ref: `smart_holder ` for details. Closely related is the addition
31
+ of ``py::trampoline_self_life_support ``, documented under
32
+ :ref: `overriding_virtuals `.
33
+
34
+ This release includes a major modernization of cross-extension-module
35
+ ABI compatibility handling. The new implementation reflects actual ABI
36
+ compatibility much more accurately than in previous versions. The details
37
+ are subtle and complex; see
38
+ `#4953 <https://github.com/pybind/pybind11/pull/4953 >`_ and
39
+ `#5439 <https://github.com/pybind/pybind11/pull/5439 >`_.
40
+
41
+ Also new in v3.0 is ``py::native_enum ``, a modern API for exposing
42
+ C++ enumerations as native Python types — typically standard-library
43
+ ``enum.Enum `` or related subclasses. This provides improved integration with
44
+ Python's enum system, compared to the older (now deprecated) ``py::enum_ ``.
45
+ See #5555 <https://github.com/pybind/pybind11/pull/5555>_ for details.
46
+
47
+ Functions exposed with pybind11 are now pickleable. This removes a
48
+ long-standing obstacle when using pybind11-bound functions with Python features
49
+ that rely on pickling, such as multiprocessing and caching tools.
50
+ See #5580 <https://github.com/pybind/pybind11/pull/5580>_ for details.
51
+
52
+ Migration Recommendations
53
+ -------------------------
54
+
55
+ We recommend migrating to pybind11 v3.0 promptly, while keeping initial
56
+ changes to a minimum. Most projects can upgrade simply by updating the
57
+ pybind11 version, without altering existing binding code.
58
+
59
+ After a short stabilization period — enough to surface any subtle issues —
60
+ you may incrementally adopt new features where appropriate:
61
+
62
+ * Use ``py::smart_holder `` and ``py::trampoline_self_life_support `` as needed,
63
+ or to improve code health. Note that ``py::classh `` is available as a
64
+ shortcut — for example, ``py::classh<Pet> `` is shorthand for
65
+ ``py::class_<Pet, py::smart_holder> ``. This is designed to enable easy
66
+ experimentation with ``py::smart_holder `` without introducing distracting
67
+ whitespace changes. In many cases, a global replacement of ``py::class_ ``
68
+ with ``py::classh `` can be an effective first step. Build failures will
69
+ quickly identify places where ``std::shared_ptr<...> `` holders need to be
70
+ removed. Runtime failures (assuming good unit test coverage) will highlight
71
+ base-and-derived class situations that require coordinated changes.
72
+
73
+ * Gradually migrate from ``py::enum_ `` to ``py::native_enum `` to improve
74
+ integration with Python's standard enum types.
75
+
76
+ There is no urgency to refactor existing, working bindings — adopt new
77
+ features as the need arises or as part of ongoing maintenance efforts.
78
+
79
+ Potential stumbling blocks when migrating to v3.0
80
+ -------------------------------------------------
81
+
82
+ The following issues are very unlikely to arise, and easy to work around:
83
+
84
+ * TODO holder caster traits specializations may be needed
85
+
86
+ * TODO enum caster traits specializations may be needed
87
+
11
88
.. _upgrade-guide-2.12 :
12
89
13
90
v2.12
0 commit comments