----------------------------
This is a big release. The sections below cover added features, efficiency
improvements, and miscellaneous fixes and improvements.
New features
^^^^^^^^^^^^
* nanobind now supports binding types that inherit from
``std::enable_shared_from_this<T>``. See the :ref:`advanced section
on object ownership <enable_shared_from_this>` for more details.
(PR `212 <https://github.com/wjakob/nanobind/pull/212>`__).
* Added a type caster between Python ``datetime``/``timedelta`` objects and
C++ ``std::chrono::duration``/``std::chrono::time_point``, ported
from pybind11. (PR `175 <https://github.com/wjakob/nanobind/pull/175>`__).
* The :cpp:class:`nb::ndarray\<..\> <ndarray>` class can now use the buffer
protocol to receive and return arrays representing read-only memory. (PR
`217 <https://github.com/wjakob/nanobind/pull/217>`__).
* Added :cpp:func:`nb::python_error::discard_as_unraisable()
<python_error::discard_as_unraisable>` as a wrapper around
``PyErr_WriteUnraisable()``. (PR `175
<https://github.com/wjakob/nanobind/pull/175>`__).
Efficiency improvements:
^^^^^^^^^^^^^^^^^^^^^^^^
* Reduced the per-instance overhead of nanobind by 1 pointer and simplified the
internal hash table types to crunch ``libnanobind``. (commit `de018d
<https://github.com/wjakob/nanobind/commit/de018db2d17905564703f1ade4aa201a22f8551f>`__).
* Supplemental type data specified via :cpp:class:`nb::supplement\<T\>()
<supplement>` is now stored directly within the type object instead of being
referenced through an indirection. (commit `d82ca9
<https://github.com/wjakob/nanobind/commit/d82ca9c14191e74dd35dd5bf15fc90f5230319fb>`__).
* Reduced the number of exception-related exports to further crunch
``libnanobind``. (commit `763962
<https://github.com/wjakob/nanobind/commit/763962b8ce76414148089ef6a68cff97d7cc66ce>`__).
* Reduced the size of nanobind type objects by 5 pointers. (PR `194
<https://github.com/wjakob/nanobind/pull/194>`__, `#195
<https://github.com/wjakob/nanobind/pull/195>`__, and commit `d82ca9
<https://github.com/wjakob/nanobind/commit/d82ca9c14191e74dd35dd5bf15fc90f5230319fb>`__).
* Internal nanobind types (``nb_type``, ``nb_static_property``, ``nb_ndarray``)
are now constructed on demand. This reduces the size of the ``libnanobind``
component in static (``NB_STATIC``) builds when those features are not used.
(commits `95e45a
<https://github.com/wjakob/nanobind/commit/95e45a4027dcbce935091533f7d41bf59e3e5fe1>`__,
`375083
<https://github.com/wjakob/nanobind/commit/37508386a1f8c346d17a0353c8152940aacde9c2>`__,
and `e033c8
<https://github.com/wjakob/nanobind/commit/e033c8fab4a14cbb9c5b0e08b1bdf49af2a9cb22>`__).
* Added a small function cache to improve code generation in limited API
builds. (commit `f0f4aa
<https://github.com/wjakob/nanobind/commit/f0f42a564995ba3bd573282674d1a6d636a048c8>`__).
* Refined compiler and linker flags across platforms to ensure compact binaries
especially in ``NB_STATIC`` builds. (commit `5ead9f
<https://github.com/wjakob/nanobind/commit/5ead9ff348a2ef0df8231e6480607a5b0623a16b>`__)
* nanobind enums now take advantage of :ref:`supplemental data <supplement>`
to improve the speed of object and name lookups. Note that this prevents
use of ``nb::supplement<T>()`` with enums for other purposes.
(PR `195 <https://github.com/wjakob/nanobind/pull/195>`__).
Miscellaneous fixes and improvements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Use the new `PEP-697 <https://peps.python.org/pep-0697/>`__ interface to
access data in type objects when compiling stable ABI3 wheels. This improves
forward compatibility (the Python team may at some point significantly
refactor the layout and internals of type objects). (PR `211
<https://github.com/wjakob/nanobind/pull/211>`__):
* Added introspection attributes ``__self__`` and ``__func__`` to nanobind
bound methods, to make them more like regular Python bound methods.
Fixed a bug where ``some_obj.method.__call__()`` would behave differently
than ``some_obj.method()``.
(PR `216 <https://github.com/wjakob/nanobind/pull/216>`__).
* Updated the implementation of :cpp:class:`nb::enum_ <enum_>` so it does
not take advantage of any private nanobind type details. As a side effect,
the construct ``nb::class_<T>(..., nb::is_enum(...))`` is no longer permitted;
use ``nb::enum_<T>(...)`` instead.
(PR `195 <https://github.com/wjakob/nanobind/pull/195>`__).
* Added the :cpp:class:`nb::type_slots_callback` class binding annotation,
similar to :cpp:class:`nb::type_slots` but allowing more dynamic choices.
(PR `195 <https://github.com/wjakob/nanobind/pull/195>`__).
* nanobind type objects now treat attributes specially whose names
begin with `. These attributes can be set once, but not
rebound or deleted. This safeguard allows a borrowed reference to
the attribute value to be safely stashed in the type supplement,
allowing arbitrary Python data associated with the type to be accessed
without a dictionary lookup while keeping this data visible to the
garbage collector. (PR `195 <https://github.com/wjakob/nanobind/pull/195>`__).
* Fixed surprising behavior in enumeration comparisons and arithmetic
(PR `207 <https://github.com/wjakob/nanobind/pull/207>`__):
* Enum equality comparisons (``==`` and ``!=``) now can only be true
if both operands have the same enum type, or if one is an enum and
the other is an ``int``. This resolves some confusing
results and ensures that enumerators of different types have a
distinct identity, which is important if they're being put into
the same set or used as keys in the same dictionary. All of the
following were previously true but will now evaluate as false:
* ``FooEnum(1) == BarEnum(1)``
* ``FooEnum(1) == 1.2``
* ``FooEnum(1) == "1"``
* Enum ordering comparisons (``<``, ``<=``, ``>=``, ``>``) and
arithmetic operations (when using the :cpp:struct:`is_arithmetic`
annotation) now require that any non-enum operand be a Python number
(an object that defines ``__int__``, ``__float__``, and/or ``__index__``)
and will avoid truncating non-integer operands to integers. Note that
unlike with equality comparisons, ordering and arithmetic operations
*do* still permit two operands that are enums of different types.
Some examples of changed behavior:
* ``FooEnum(1) < 1.2`` is now true (used to be false)
* ``FooEnum(2) * 1.5`` is now 3.0 (used to be 2)
* ``FooEnum(3) - "2"`` now raises an exception (used to be 1)
* Enum comparisons and arithmetic operations with unsupported types
now return `NotImplemented` rather than raising an exception.
This means equality comparisons such as ``some_enum == None`` will
return unequal rather than failing; order comparisons such as
``some_enum < None`` will still fail, but now with a more
informative error.
* ABI version 8.