Skip to content

Commit

Permalink
naming: changed nb::weak_referenceable to ``nb::is_weak_reference…
Browse files Browse the repository at this point in the history
…able``
wjakob committed Feb 23, 2024
1 parent 10fce12 commit 3562f69
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/api_core.rst
Original file line number Diff line number Diff line change
@@ -1685,7 +1685,7 @@ parameter of the constructor :cpp:func:`class_::class_`.

Indicate that instances of a type require a Python dictionary to support the dynamic addition of attributes.

.. cpp:struct:: weak_referenceable
.. cpp:struct:: is_weak_referenceable

Indicate that instances of a type require weak reference list so that they
can be referenced by the Python ``weakref`` type.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ Version 1.9.0 (Feb 18, 2024)
----------------------------

* Nanobind instances can now be :ref:`made weak-referenceable <weak_refs>` by
specifying the :cpp:class:`nb::weak_referenceable <weak_referenceable>` tag
specifying the :cpp:class:`nb::is_weak_referenceable <is_weak_referenceable>` tag
in the :cpp:class:`nb::class_\<..\> <class_>` constructor. (PR `#335
<https://github.com/wjakob/nanobind/pull/335>`__, commit `fc7709
<https://github.com/wjakob/nanobind/commit/fc770930468313e5a69364cfd1bbdab9bc0ab208>`__).
6 changes: 3 additions & 3 deletions docs/classes.rst
Original file line number Diff line number Diff line change
@@ -374,14 +374,14 @@ Weak references
By default, nanobind instances cannot be referenced via Python's ``weakref``
class, and attempting to do so will raise an exception.

To support this, add the :class:`nb::weak_referenceable
<weak_referenceable>` tag to the :class:`nb::class_ <class_>` constructor.
To support this, add the :class:`nb::is_weak_referenceable
<is_weak_referenceable>` tag to the :class:`nb::class_ <class_>` constructor.
Note that this will increase the size of every instance by ``sizeof(void*)``
due to the need to store a weak reference list.

.. code-block:: cpp
nb::class_<Pet>(m, "Pet", nb::weak_referenceable());
nb::class_<Pet>(m, "Pet", nb::is_weak_referenceable());
.. _inheriting_in_python:

2 changes: 1 addition & 1 deletion include/nanobind/nb_attr.h
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ template <typename... Ts> struct call_guard {
};

struct dynamic_attr {};
struct weak_referenceable {};
struct is_weak_referenceable {};
struct is_method {};
struct is_implicit {};
struct is_operator {};
4 changes: 2 additions & 2 deletions include/nanobind/nb_class.h
Original file line number Diff line number Diff line change
@@ -156,8 +156,8 @@ NB_INLINE void type_extra_apply(type_init_data &t, dynamic_attr) {
t.flags |= (uint32_t) type_flags::has_dynamic_attr;
}

NB_INLINE void type_extra_apply(type_data & t, weak_referenceable) {
t.flags |= (uint32_t)type_flags::is_weak_referenceable;
NB_INLINE void type_extra_apply(type_data & t, is_weak_referenceable) {
t.flags |= (uint32_t) type_flags::is_weak_referenceable;
}

template <typename T>
4 changes: 2 additions & 2 deletions tests/test_classes.cpp
Original file line number Diff line number Diff line change
@@ -559,10 +559,10 @@ NB_MODULE(test_classes_ext, m) {
[](IncrementingStruct &s) { return new Struct(s.i + 100); },
nb::keep_alive<0, 1>());

nb::class_<StructWithWeakrefs, Struct>(m, "StructWithWeakrefs", nb::weak_referenceable())
nb::class_<StructWithWeakrefs, Struct>(m, "StructWithWeakrefs", nb::is_weak_referenceable())
.def(nb::init<int>());

nb::class_<StructWithWeakrefsAndDynamicAttrs, Struct>(m, "StructWithWeakrefsAndDynamicAttrs",
nb::weak_referenceable(), nb::dynamic_attr())
nb::is_weak_referenceable(), nb::dynamic_attr())
.def(nb::init<int>());
}

0 comments on commit 3562f69

Please sign in to comment.