Nanobind

Latest version: v2.2.0

Safety actively analyzes 682471 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 6

1.7.0

----------------------------

New features
^^^^^^^^^^^^

* The nd-array class :cpp:class:`nb::ndarray\<T\> <ndarray>` now supports
complex-valued ``T`` (e.g., ``std::complex<double>``). For this, the header
file ``nanobind/stl/complex.h`` must be included. (PR `319
<https://github.com/wjakob/nanobind/pull/319>`__, commit `6cbd13
<https://github.com/wjakob/nanobind/commit/6cbd1387753ea8f519ac0fe2242f0a54dd670ede>`__).

* Added the function :cpp:func:`nb::del() <del>`, which takes an arbitrary
accessor object as input and tries to delete the associated entry.
The C++ statement

.. code-block:: cpp

nb::del(o[key]);

is equivalent to ``del o[key]`` in Python. (commit `4dd745
<https://github.com/wjakob/nanobind/commit/4dd74596ac7b0f850cb0144f42a438124b91720c>`__).

* Exposed several convenience functions for raising exceptions as public API:
:cpp:func:`nb::raise <raise>`, :cpp:func:`nb::raise_type_error
<raise_type_error>`, and :cpp:func:`nb::raise_python_error
<raise_python_error>`. (commit `0b7f3b
<https://github.com/wjakob/nanobind/commit/0b7f3b1d2a182bda8b95826a3f98cc3e2d0402db>`__).

* Added :cpp:func:`nb::globals() <globals>`. (PR `311
<https://github.com/wjakob/nanobind/pull/311>`__, commit `f0a9eb
<https://github.com/wjakob/nanobind/commit/f0a9ebd9cd384ac554312247526b120102563e53>`__).

* The ``char*`` type caster now accepts ``nullptr`` and converts it into a
Python ``None`` object. (PR `318
<https://github.com/wjakob/nanobind/pull/317>`__, commit `30a6ba
<https://github.com/wjakob/nanobind/commit/30a6bac97a89bfafad82c2c5b6ef4516c00c35d6>`__).

* Added the function :cpp:func:`nb::is_alive() <is_alive>`, which returns
``false`` when nanobind was destructed by Python (e.g., during interpreter
shutdown) making further use of the API illegal. (commit `b431d0
<https://github.com/wjakob/nanobind/commit/b431d040f7b0585e9901856ee6c9b72281a37fa8>`__).

* Minor fixes and improvements.

* ABI version 11.

Bugfixes
^^^^^^^^

* The behavior of the :cpp:class:`nb::keep_alive\<Nurse, Patient\>
<keep_alive>` function binding annotation was changed as follows: when the
function call requires the implicit conversion of an argument, the lifetime
constraint now applies to the newly produced argument instead of the original
object. The change was rolled into a minor release since the former behavior
is arguably undesirable and dangerous. (commit `9d4b2e
<https://github.com/wjakob/nanobind/commit/9d4b2e317dbf32efab4ed41b6c275f9dbbbcf29f>`__).

* STL type casters previously raised an exception when casting a Python container
containing a ``None`` element into a C++ container that was not able to
represent ``nullptr`` (e.g., ``std::vector<T>`` instead of
``std::vector<T*>``). However, this exception was raised in a context where
exceptions were not allowed, causing the process to be ``abort()``-ed, which
is very bad. This issue is now fixed, and such conversions are refused. (PR
`318 <https://github.com/wjakob/nanobind/pull/318>`__, commits `d1ad3b
<https://github.com/wjakob/nanobind/commit/d1ad3b91346a1566f42fdf194a3ed9c3eeec5858>`__
and `5f25ae
<https://github.com/wjakob/nanobind/commit/5f25ae0eb9691fbe03a20bcb9f604277ccc1884b>`__).

* The STL sequence casters (``std::vector<T>``, etc.) now refuse to unpack
``str`` and ``bytes`` objects analogous to pybind11. (commit `7e4a88
<https://github.com/wjakob/nanobind/commit/7e4a88b7ccc047ce34ae8ae99492d46b1acf341a>`__).

1.6.2

---------------------------

* Added a missing include file used by the new intrusive reference counting
sample implementation from v1.6.0. (commit `31d115
<https://github.com/wjakob/nanobind/commit/31d115fce310475fed0f539b9446cc41ba9ff4d4>`__).

1.6.1

---------------------------

* Added missing namespace declaration to the :cpp:class:`ref` intrusive
reference counting RAII helper class added in version 1.6.0. (commit `3ba352
<https://github.com/wjakob/nanobind/commit/3ba3522e99c8f1f4bcc7c172abd2006eeaa8eaf8>`__).

1.6.0

---------------------------

New features
^^^^^^^^^^^^

* Several :cpp:class:`nb::ndarray\<..\> <ndarray>` improvements:

1. CPU loops involving nanobind nd-arrays weren't getting properly vectorized.
This release of nanobind adds *views*, which provide an efficient
abstraction that enables better code generation. See the documentation
section on :ref:`array views <ndarray-views>` for details.
(commit `8f602e
<https://github.com/wjakob/nanobind/commit/8f602e187b0634e1df13ba370352cf092e9042c0>`__).

2. Added support for nonstandard arithmetic types (e.g., ``__int128`` or
``__fp16``) in nd-arrays. See the :ref:`documentation section
<ndarray-nonstandard>` for details. (commit `49eab2
<https://github.com/wjakob/nanobind/commit/49eab2845530f84a1f029c5c1c5541ab3c1f9adc>`__).

3. Shape constraints like :cpp:class:`nb::shape\<nb::any, nb::any, nb::any\>
<shape>` are tedious to write. Now, there is a shorter form:
:cpp:class:`nb::ndim\<3\> <ndim>`. (commit `1350a5
<https://github.com/wjakob/nanobind/commit/1350a5e15b28e80ffc2130a779f3b8c559ddb620>`__).

4. Added an explicit constructor that can be used to add or remove nd-array
constraints. (commit `a1ac207
<https://github.com/wjakob/nanobind/commit/a1ac207ab82206b8e50fe456f577c02270014fb3>`__).

* Added the wrapper class :cpp:class:`nb::weakref <weakref>`. (commit `78887f
<https://github.com/wjakob/nanobind/commit/78887fc167196a7568a5cef8f8dfbbee09aa7dc4>`__).

* Added the methods :cpp:func:`nb::dict::contains() <dict::contains>` and
:cpp:func:`nb::mapping::contains() <mapping::contains>` to the Python type
wrappers. (commit `64d87a
<https://github.com/wjakob/nanobind/commit/64d87ae01355c247123613f140cef8e71bc98fc7>`__).

* Added :cpp:func:`nb::exec() <exec>` and :cpp:func:`nb:eval() <eval>`. (PR `299
<https://github.com/wjakob/nanobind/pull/299>`__).

* Added a type caster for ``std::complex<T>``. (PR `292
<https://github.com/wjakob/nanobind/pull/292>`__, commit `dcbed4
<https://github.com/wjakob/nanobind/commit/dcbed4fe1500383ad1f4dff47cacbf0f2e6b1d3f>`__).

* Added an officially supported sample implementation of :ref:`intrusive
reference counting <intrusive>` via the :cpp:class:`intrusive_counter`
:cpp:class:`intrusive_base`, and :cpp:class:`ref` classes. (commit `3fa1af
<https://github.com/wjakob/nanobind/commit/3fa1af5e9e6fd0b08d13e16bb425a18963854829>`__).

Bugfixes
^^^^^^^^

* Fixed a serious issue involving combinations of bound types (e.g., ``T``) and
type casters (e.g., ``std::vector<T>``), where nanobind was too aggressive in
its use of *move semantics*. Calling a bound function from Python taking such
a list (e.g., ``f([t1, t2, ..])``) would destruct ``t1, t2, ..`` if the type
``T`` exposed a move constructor, which is highly non-intuitive and no
longer happens as of this fix.

Further investigation also revealed inefficiencies in the previous
implementation where moves were actually possible but not done (e.g., for
functions taking an STL vector by value). Some binding projects may see
speedups as a consequence of this change. (issue `307
<https://github.com/wjakob/nanobind/issues/307>`__, commit `122015
<https://github.com/wjakob/nanobind/commit/1220156961ce2d0c96a525f3c27b88e824b997ce>`__).

1.5.2

----------------------------

* Fixed a severe issue with inheritance of the ``Py_TPFLAGS_HAVE_GC`` flag
affecting classes that derive from other classes with a
:cpp:class:`nb::dynamic_attr <dynamic_attr>` annotation. (issue `279
<https://github.com/wjakob/nanobind/issues/279>`__, commit `dbedad
<https://github.com/wjakob/nanobind/commit/dbedadc294a7529bf401f01dbc97d4b47b677bc9>`__).
* Implicit conversion of nd-arrays to conform to contiguity constraints such as
:cpp:class:`c_contig` and :cpp:class:`f_contig` previously failed in some
cases that are now addressed. (issue `278
<https://github.com/wjakob/nanobind/issues/278>`__ commit `ed929b
<https://github.com/wjakob/nanobind/commit/ed929b7c6789e7d5e1760d515bc23ce6f7cedf8c>`__).

1.5.1

----------------------------

* Fixed serious reference counting issue introduced in nanobind version 1.5.0,
which affected the functions :cpp:func:`python_error::traceback()` and
:cpp:func:`python_error::what()`, causing undefined behavior via
use-after-free. Also addressed an unrelated minor UB sanitizer warning.
(issue `277 <https://github.com/wjakob/nanobind/issues/277>`__, commits
`30d30c
<https://github.com/wjakob/nanobind/commit/30d30caaa3e834122944b28833b9c0315ef19a5d>`__
and `c48b18
<https://github.com/wjakob/nanobind/commit/c48b180834b4929f2f77ce658f2a50ee78482fb7>`__).
* Extended the internal data structure tag so that it isolates different MSVC
versions from each other (they are often not ABI compatible, see pybind11
issue `4779 <https://github.com/pybind/pybind11/pull/4779>`__). This means
that nanobind 1.5.1 effectively bumps the ABI version to "10.5" when
compiling for MSVC, and the internals will be isolated from extensions built
with nanobind v1.5.0 or older. (commit `c7f3cd
<https://github.com/wjakob/nanobind/commit/c7f3cd6a7023dec55c63b995ba50c9f5d4b9147a>`__).
* Incorporated fixes so that nanobind works with PyPy 3.10. (commits `fb5508
<https://github.com/wjakob/nanobind/commit/fb5508955e1b1455adfe1372b49748ba706b4d87>`__
and `2ed10a
<https://github.com/wjakob/nanobind/commit/2ed108a73bd5fbe0e1c43a8db07e40a165fc265f>`__).
* Fixed type caster for ``std::vector<bool>``. (PR `256
<https://github.com/wjakob/nanobind/pull/256>`__).
* Fixed compilation in debug mode on MSVC. (PR `253
<https://github.com/wjakob/nanobind/pull/253>`__).

Page 2 of 6

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.