@@ -13,25 +13,73 @@ modernization and other useful information.
13
13
v3.0
14
14
====
15
15
16
- PENDING CLEANUP:
17
- * remove_ruff_ignore_E501
18
- * tests for holder caster traits
19
- * refine holder compat errors
20
- * move "Be careful" section from smart_ptrs.rst
21
- * remove experimental/optional
22
-
23
- EXPLAIN:
24
- * How to migrate to v3? — (almost) nothing is expected to break, except ABI compatibility with the 2.x series
25
- * Explain ABI overhaul
26
- * If it's not broken, don't fix it ... maybe later?
27
- * What are the Pros/Cons/Pitfalls of migrating the existing code base to ``py::classh ``?
28
- * What is the recommended workflow for migrating? (Search&Replace ``py::class_ `` -> ``py::classh `` and add base class trampolines or anything else?)
29
- * ``py::smart_holder ``, ``py::classh ``
30
- * ``py::enum_ `` → ``py::native_enum ``
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
+ TODO ADD WARNINGS:
80
+ * std::enabled_shared_from_this private inheritance
31
81
* holder caster traits specializations may be needed
32
82
* enum caster traits specializations may be needed
33
- * std::enabled_shared_from_this private inheritance
34
- * wrapped functions are now pickleable
35
83
36
84
.. _upgrade-guide-2.12 :
37
85
0 commit comments