docs: show nogil in most examples (#5770)

Created using [mini-swe-agent](https://mini-swe-agent.com) and the propmt:

I'd like to find usages of PYBIND11_MODULE in the docs folder and add py::mod_gil_not_used() as a third argument if there ar
e only two arguments. These are examples, and it's really a good idea to always include that now.

I removed a few of the changes.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner
2025-07-27 23:08:11 -06:00
committed by GitHub
parent 33533ff3f8
commit 6972597c9b
9 changed files with 15 additions and 16 deletions

View File

@@ -108,7 +108,7 @@ type is explicitly allowed.
} // namespace pybind11
// Bind the negate function
PYBIND11_MODULE(docs_advanced_cast_custom, m) { m.def("negate", user_space::negate); }
PYBIND11_MODULE(docs_advanced_cast_custom, m, py::mod_gil_not_used()) { m.def("negate", user_space::negate); }
.. note::

View File

@@ -56,7 +56,7 @@ trivial to generate binding code for all of these functions.
#include <pybind11/functional.h>
PYBIND11_MODULE(example, m) {
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
m.def("func_arg", &func_arg);
m.def("func_ret", &func_ret);
m.def("func_cpp", &func_cpp);

View File

@@ -45,7 +45,7 @@ Normally, the binding code for these classes would look as follows:
.. code-block:: cpp
PYBIND11_MODULE(example, m) {
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Animal>(m, "Animal")
.def("go", &Animal::go);
@@ -112,7 +112,7 @@ The binding code also needs a few minor adaptations (highlighted):
.. code-block:: cpp
:emphasize-lines: 2,3
PYBIND11_MODULE(example, m) {
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Animal, PyAnimal /* <--- trampoline */, py::smart_holder>(m, "Animal")
.def(py::init<>())
.def("go", &Animal::go);
@@ -774,7 +774,7 @@ to Python.
#include <pybind11/operators.h>
PYBIND11_MODULE(example, m) {
PYBIND11_MODULE(example, m, py::mod_gil_not_used()) {
py::class_<Vector2>(m, "Vector2")
.def(py::init<float, float>())
.def(py::self + py::self)

View File

@@ -217,7 +217,7 @@ expects the type followed by field names:
};
// ...
PYBIND11_MODULE(test, m) {
PYBIND11_MODULE(test, m, py::mod_gil_not_used()) {
// ...
PYBIND11_NUMPY_DTYPE(A, x, y);
@@ -351,7 +351,7 @@ simply using ``vectorize``).
return result;
}
PYBIND11_MODULE(test, m) {
PYBIND11_MODULE(test, m, py::mod_gil_not_used()) {
m.def("add_arrays", &add_arrays, "Add two NumPy arrays");
}