Commit Graph

3012 Commits

Author SHA1 Message Date
Henry Schreiner
d25e91fb8f fix(cmake): warning about missing file (#5612)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-04-10 17:48:16 -04:00
Ralf W. Grosse-Kunstleve
31e52b2cd3 Add holder caster traits tests in test_smart_ptr.cpp,py (#5603)
* Add test_smart_ptr.cpp,py holder_caster_traits_test

* [skip ci] Resolve clang-tidy error with a NOLINT

Tested with clang-tidy locally.
2025-04-10 12:37:50 -07:00
Ralf W. Grosse-Kunstleve
e38beb96c4 [skip ci] Move "Pitfalls with raw pointers and shared ownership" section to a more prominent location. (#5611) 2025-04-10 12:12:00 -07:00
Ralf W. Grosse-Kunstleve
1bd1d1ced8 Change PyCFunction cast in function_record_pyobject.h to sidestep unhelpful compiler warnings. (#5608)
* Change PyCFunction cast in function_record_pyobject.h to sidestep unhelpful compiler warnings.

* Resolve clang-tidy error

/__w/pybind11/pybind11/include/pybind11/detail/function_record_pyobject.h:41:39: error: do not cast 'PyObject *(PyObject *, PyObject *, PyObject *)' (aka '_object *(_object *, _object *, _object *)') to 'PyCFunction' (aka '_object *(*)(_object *, _object *)') through 'void *' [bugprone-casting-through-void,-warnings-as-errors]
   41 |         reinterpret_cast<PyCFunction>(reinterpret_cast<void *>(reduce_ex_impl)),
      |                                       ^
2025-04-10 12:09:59 -07:00
Michael Šimáček
708ce4d9c7 Fix GraalPy version parsing on dev builds (#5609)
* Fix GraalPy version parsing on dev builds

* Unskip test on GraalPy
2025-04-09 09:09:15 -07:00
Ralf W. Grosse-Kunstleve
a28ea8ccc5 Eliminate pybindit namespace (#5607)
* Factor out pybind11/detail/pybind11_namespace_macros.h from pybind11/detail/common.h

* Eliminate `pybindit` namespace, use pybind11/detail/pybind11_namespace_macros.h instead.

* Fix oversight: add pybind11_namespace_macros.h in tests/extra_python_package/test_files.py

* [skip ci] Add copyright notice.
2025-04-08 20:46:24 -07:00
Henry Schreiner
6d1f28fe2b feat: remove make_simple_namespace (#5597)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-04-08 23:44:18 -04:00
Henry Schreiner
73ad3099fb fix: fully deprecate get_type_of (deprecated in 2.6 but no warning (#5596)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-04-08 23:43:49 -04:00
Henry Schreiner
b70b8eb332 chore: require pytest 6 consistently (#5599)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-04-04 12:35:55 -07:00
Henry Schreiner
fdab860a32 feat: drop PYBIND11_NUMPY_1_ONLY (#5595)
* feat: drop PYBIND11_NUMPY_1_ONLY

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Add #error "PYBIND11_NUMPY_1_ONLY is no longer supported." in pybind11/numpy.h

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-04-03 22:08:56 -04:00
Henry Schreiner
55b1357d8e chore: update nox and test deps (#5594)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-04-02 08:24:15 -04:00
Henry Schreiner
8ef10a0ec9 ci: update to GraalPy 24.2 and mention in README (#5586)
* ci: update to GraalPy 24.2 and mention in README

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: update for GRAALPY 24.2 and better printout

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: use __graalpython__ for version number

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update README.rst

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-31 22:50:55 -04:00
Henry Schreiner
d27fdaa272 chore: update for CMake 4.0 (#5593)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-31 22:50:40 -04:00
Ralf W. Grosse-Kunstleve
e03ec30632 Squashed function_record_std_launder/manuscript — 57b9a0af815d19b236b74be06a172bc5c9956618 — 2025-03-30 20:14:21 -0700 (#5592)
[Browse function_record_std_launder/manuscript tree](57b9a0af81)

[Browse function_record_std_launder/manuscript commits](57b9a0af81/)
2025-03-31 15:54:38 -07:00
Ralf W. Grosse-Kunstleve
a34fcdc48d [ci skip] Response to question by gh-henryiii (https://github.com/pybind/pybind11/pull/5580#discussion_r2019137216) (#5591) 2025-03-30 19:56:07 -07:00
Ralf W. Grosse-Kunstleve
8726ed22d8 Fix build failure when shared_ptr<T> points to private std::enable_shared_from_this base (#5590)
* Squashed private_esft/manuscript — 3f2b1201b830d9e431448bd8f5fe577afaa02dbf — 2025-03-30 12:38:30 -0700

[Browse private_esft/manuscript tree](3f2b1201b8)

[Browse private_esft/manuscript commits](3f2b1201b8/)

* Remove mention of ChatGPT

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-03-30 19:43:40 -07:00
Ralf W. Grosse-Kunstleve
e7e5d6e5bb Make wrapped C++ functions pickleable (#5580)
* Backport of https://github.com/google/pybind11clif/pull/30099

* Add back `PYBIND11_WARNING_DISABLE_CLANG("-Wcast-function-type-mismatch")`

macos-13 • brew install llvm

```
/Users/runner/work/pybind11/pybind11/include/pybind11/detail/function_record_pyobject.h:40:26: error: cast from 'PyObject *(*)(PyObject *, PyObject *, PyObject *)' (aka '_object *(*)(_object *, _object *, _object *)') to 'PyCFunction' (aka '_object *(*)(_object *, _object *)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]
   40 |     = {{"__reduce_ex__", (PyCFunction) reduce_ex_impl, METH_VARARGS | METH_KEYWORDS, nullptr},
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

* Remove obsolete `PY_VERSION_HEX >= 0x03080000` (discovered by gh-henryiii)
2025-03-28 11:50:37 -07:00
Henry Schreiner
8f00d1eea0 fix: set __file__ on submodules (#5584)
* fix: set __file__ on submodules

The docs state ['The caller is responsible for setting a `__file__` attribute'](https://docs.python.org/3/c-api/module.html), but we
were not doing that, which interferes with pickling objects in submodules using cloudpickle. Users previously had to set the `__file__` attributes manually,
such as in 1fbbe1632e/src/boost_histogram/histogram.py (L83-L90).

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* fix: support GraalPy

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* fix: workaround only for GraalPython

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Add GRAALPY_VERSION_NUM to GraalPy workaround

* Fix "GRAALPY_VERSION_NUM not defined" issue

```
/Users/runner/work/pybind11/pybind11/include/pybind11/pybind11.h:1340:32: error: 'GRAALPY_VERSION_NUM' is not defined, evaluates to 0 [-Werror,-Wundef]
                               ^
```

Related ChatGPT conversation: https://chatgpt.com/share/67e6cb99-84b0-8008-99d6-aadc70242cf3

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-03-28 09:57:39 -07:00
Ralf W. Grosse-Kunstleve
c1cd022f16 tests: Add test for boost::histogram::func_transform situation. (#5582)
* Add test for boost::histogram::func_transform situation.

* Resolve clang-tidy errors

```
/__w/pybind11/pybind11/tests/test_callbacks.cpp:33:9: error: 'auto rec' can be declared as 'auto *rec' [readability-qualified-auto,-warnings-as-errors]
   33 |         auto rec = c.get_pointer<py::detail::function_record>();
      |         ^~~~
      |         auto *
/__w/pybind11/pybind11/tests/test_callbacks.cpp:41:13: error: 'auto cap' can be declared as 'auto *cap' [readability-qualified-auto,-warnings-as-errors]
   41 |             auto cap = reinterpret_cast<capture *>(&rec->data);
      |             ^~~~
      |             auto *
```

* Replace `apply_custom_transform()` implementation using `make_caster<std::function<raw_t>>`

* Add func_is_stateless_with_exact_type feature in pybind11/functional.h

* tests: use std::function::target

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* style: pre-commit fixes

* Resolve clang-tidy error

```
/__w/pybind11/pybind11/tests/test_callbacks.cpp:33:5: error: 'auto cfunc' can be declared as 'auto *cfunc' [readability-qualified-auto,-warnings-as-errors]
   33 |     auto cfunc = func.target<raw_t *>();
      |     ^~~~
      |     auto *
```

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-28 11:36:02 -04:00
Ralf W. Grosse-Kunstleve
f365314ec0 Enable Conversions Between Native Python Enum Types and C++ Enums (#5555)
* Apply smart_holder-branch-based PR #5280 on top of master.

* Add pytest.skip("GraalPy does not raise UnicodeDecodeError")

* Add `parent_scope` as first argument to `py::native_enum` ctor.

* Replace `operator+=` API with `.finalize()` API. The error messages still need cleanup.

* Resolve clang-tidy performance-unnecessary-value-param errors

* Rename (effectively) native_enum_add_to_parent() -> finalize()

* Update error message: pybind11::native_enum<...>("Fake", ...): MISSING .finalize()

* Pass py::module_ by reference to resolve clang-tidy errors (this is entirely inconsequential otherwise for all practical purposes).

* test_native_enum_correct_use_failure -> test_native_enum_missing_finalize_failure

* Add test_native_enum_double_finalize(), test_native_enum_value_after_finalize()

* Clean up public/protected API.

* [ci skip] Update the Enumerations section in classes.rst

* Rename `py::native_enum_kind` → `py::enum_kind` as suggested by gh-henryiii:

https://github.com/pybind/pybind11/pull/5555#issuecomment-2711672335

* Experiment: StrEnum

enum.StrEnum does not map to C++ enum:

* https://chatgpt.com/share/67d5e965-ccb0-8008-95b7-0df2502309b3

```
============================= test session starts ==============================
platform linux -- Python 3.12.3, pytest-8.3.3, pluggy-1.5.0
C++ Info: 13.3.0 C++20 __pybind11_internals_v10000000_system_libstdcpp_gxx_abi_1xxx_use_cxx11_abi_1__ PYBIND11_SIMPLE_GIL_MANAGEMENT=False PYBIND11_NUMPY_1_ONLY=False
configfile: pytest.ini
plugins: parallel-0.1.1, xdist-3.6.1
collected 40 items / 39 deselected / 1 selected

test_native_enum.py F                                                    [100%]

=================================== FAILURES ===================================
________________________ test_native_enum_StrEnum_greek ________________________

    def test_native_enum_StrEnum_greek():
        assert not hasattr(m, "greek")
>       m.native_enum_StrEnum_greek(m)

test_native_enum.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.12/enum.py:764: in __call__
    return cls._create_(
        boundary   = None
        cls        = <enum 'StrEnum'>
        module     = None
        names      = [('Alpha', 10), ('Omega', 20)]
        qualname   = None
        start      = 1
        type       = None
        value      = 'greek'
        values     = ()
/usr/lib/python3.12/enum.py:917: in _create_
    return metacls.__new__(metacls, class_name, bases, classdict, boundary=boundary)
        _          = <class 'str'>
        bases      = (<enum 'StrEnum'>,)
        boundary   = None
        class_name = 'greek'
        classdict  = {'_generate_next_value_': <function StrEnum._generate_next_value_ at 0x701ec1711e40>, 'Alpha': 10, 'Omega': 20, '__module__': 'test_native_enum'}
        cls        = <enum 'StrEnum'>
        first_enum = <enum 'StrEnum'>
        item       = ('Omega', 20)
        member_name = 'Omega'
        member_value = 20
        metacls    = <class 'enum.EnumType'>
        module     = 'test_native_enum'
        names      = [('Alpha', 10), ('Omega', 20)]
        qualname   = None
        start      = 1
        type       = None
/usr/lib/python3.12/enum.py:606: in __new__
    raise exc.with_traceback(tb)
        __class__  = <class 'enum.EnumType'>
        __new__    = <function StrEnum.__new__ at 0x701ec1711da0>
        _gnv       = <staticmethod(<function StrEnum._generate_next_value_ at 0x701ec1711e40>)>
        _order_    = None
        _simple    = False
        bases      = (<enum 'StrEnum'>,)
        boundary   = None
        classdict  = {'Alpha': <enum._proto_member object at 0x701ebc74f9b0>, 'Omega': <enum._proto_member object at 0x701ebc74cce0>, '__module__': 'test_native_enum', '_all_bits_': 0, ...}
        cls        = 'greek'
        exc        = TypeError('10 is not a string')
        first_enum = <enum 'StrEnum'>
        ignore     = ['_ignore_']
        invalid_names = set()
        key        = '_ignore_'
        kwds       = {}
        member_names = {'Alpha': None, 'Omega': None}
        member_type = <class 'str'>
        metacls    = <class 'enum.EnumType'>
        name       = 'Omega'
        save_new   = False
        tb         = <traceback object at 0x701ebc7a6cc0>
        use_args   = True
        value      = 20
/usr/lib/python3.12/enum.py:596: in __new__
    enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
        __class__  = <class 'enum.EnumType'>
        __new__    = <function StrEnum.__new__ at 0x701ec1711da0>
        _gnv       = <staticmethod(<function StrEnum._generate_next_value_ at 0x701ec1711e40>)>
        _order_    = None
        _simple    = False
        bases      = (<enum 'StrEnum'>,)
        boundary   = None
        classdict  = {'Alpha': <enum._proto_member object at 0x701ebc74f9b0>, 'Omega': <enum._proto_member object at 0x701ebc74cce0>, '__module__': 'test_native_enum', '_all_bits_': 0, ...}
        cls        = 'greek'
        exc        = TypeError('10 is not a string')
        first_enum = <enum 'StrEnum'>
        ignore     = ['_ignore_']
        invalid_names = set()
        key        = '_ignore_'
        kwds       = {}
        member_names = {'Alpha': None, 'Omega': None}
        member_type = <class 'str'>
        metacls    = <class 'enum.EnumType'>
        name       = 'Omega'
        save_new   = False
        tb         = <traceback object at 0x701ebc7a6cc0>
        use_args   = True
        value      = 20
/usr/lib/python3.12/enum.py:271: in __set_name__
    enum_member = enum_class._new_member_(enum_class, *args)
        args       = (10,)
        enum_class = <enum 'greek'>
        member_name = 'Alpha'
        self       = <enum._proto_member object at 0x701ebc74f9b0>
        value      = 10
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <enum 'greek'>, values = (10,)

    def __new__(cls, *values):
        "values must already be of type `str`"
        if len(values) > 3:
            raise TypeError('too many arguments for str(): %r' % (values, ))
        if len(values) == 1:
            # it must be a string
            if not isinstance(values[0], str):
>               raise TypeError('%r is not a string' % (values[0], ))
E               TypeError: 10 is not a string

cls        = <enum 'greek'>
values     = (10,)

/usr/lib/python3.12/enum.py:1322: TypeError
=========================== short test summary info ============================
FAILED test_native_enum.py::test_native_enum_StrEnum_greek - TypeError: 10 is...
======================= 1 failed, 39 deselected in 0.07s =======================

ERROR: completed_process.returncode=1
```

* Remove StrEnum code.

* Make enum_kind::Enum the default kind.

* Catch redundant .export_values() calls.

* [ci skip] Add back original documentation for `py::enum_` under new advanced/deprecated.rst

* [ci skip] Add documentation for `py::enum_kind` and `py::detail::type_caster_enum_type_enabled`

* Rename `Type` to `EnumType` for readability.

* Eliminate py::enum_kind, use "enum.Enum", "enum.IntEnum" directly. This is still WIP.

* EXPERIMENTAL StrEnum code. To be removed.

* Remove experimental StrEnum code:

My judgement: Supporting StrEnum is maybe nice, but not very valuable. I don't think it is worth the extra C++ code.

A level of indirection would need to be managed, e.g.

    RED   ↔ Python "r" ↔ C++ 0
    Green ↔ Python "g" ↔ C++ 1

These mappings would need to be stored and processed.

* Add test with enum.IntFlag (no production code changes required).

* First import_or_getattr() implementation (dedicated tests are still missing).

* Fix import_or_getattr() implementation, add tests, fix clang-tidy errors.

* [ci skip] Update classes.rst: replace `py::enum_kind` with `native_type_name`

* For "constructor similar to that of enum.Enum" point to https://docs.python.org/3/howto/enum.html#functional-api, as suggested by gh-timohl (https://github.com/pybind/pybind11/pull/5555#discussion_r2009277507).

* Advertise Enum, IntEnum, Flag, IntFlags are compatible stdlib enum types in the documentation (as suggested by gh-timohl, https://github.com/pybind/pybind11/pull/5555#pullrequestreview-2708832587); add test for enum.Flag to ensure that is actually true.
2025-03-24 20:31:59 -07:00
Ralf W. Grosse-Kunstleve
48eb5ad9b9 Remove PyPy 3.8 and 3.9 testing. Make a pass through the entire repo to remove obviously obsolete workarounds for PyPy < 3.10. (#5578) 2025-03-23 20:35:14 -07:00
Michael Carlstrom
566894d5f1 Fix null pointer dereference in attr_with_type_hint (#5576)
* Fix regression

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Request changes and fix for func_rec nullptr

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Fix function_record call

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* try typedef forward declaration

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* refactor

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* remove from .py file

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* address feedback

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Fix `e.j.` → `e.g.` typo.

---------

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-03-23 10:09:46 -07:00
b-pass
974eba77a5 Change PYBIND11_MODULE to use multi-phase init (PEP 489) (#5574)
* Change PYBIND11_MODULE to use multi-phase init

Use slots to specify advanced init options (currently just Py_GIL_NOT_USED).
Adds a new function `initialize_multiphase_module_def` to module_, similar to the existing (unchanged) create_extension_module.

* Avoid dynamic allocation and non-trivial destruction

... by using an std::array for the slots.

* Oops, stray cut and paste character

* Remove assignment from placement new, change size fo slots array

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-21 08:03:34 -07:00
Matti Picus
97022f83ce TEST: test passes on PyPy macOS (#5569)
* test passes on PyPy macOS

* revert, set strict=False instead

* Tweak condition for strict

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

---------

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2025-03-20 22:41:33 -07:00
Michael Carlstrom
6412615ebb Update NDArray[object] to be NDArray[numpy.object_] (#5571)
* fix numpy.object_

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-20 20:57:51 -07:00
Henry Schreiner
bb504dd809 fix: FindPython by default logic error (#5561)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-20 17:38:30 -04:00
Henry Schreiner
655c60d84c docs: fix incorrect name (PYBIND11_NEWPYTHON) (#5570) 2025-03-19 12:45:26 -04:00
Tim Ohliger
9f08625d60 Updated py::capsule type hint to use new types.CapsuleType (#5567) 2025-03-18 11:29:57 -07:00
Michael Carlstrom
dfe7e65b45 feat(types): Use typing.SupportsInt and typing.SupportsFloat and fix other typing based bugs. (#5540)
* init

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* remove import

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* remove uneeded function

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Add missing import

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Fix type behind detailed_message_enabled flag

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Fix type behind detailed_message_enabled flag

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Add io_name comment

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Extra loops to single function

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Remove unneeded forward declaration

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Switch variable name away from macro

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Switch variable name away from macro

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* Switch variable name away from macro

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* clang-tidy

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* remove stack import

* Fix bug in std::function Callable type

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* remove is_annotation argument

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

* Update function name and arg names

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* style: pre-commit fixes

---------

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-18 07:56:34 -07:00
Henry Schreiner
16b5abd428 chore: bump catch download to 2.13.10 (#5568)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-17 17:18:00 -04:00
Henry Schreiner
d28904f12e feat: FindPython by default (#5553)
* feat: FindPython by default

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Update tools/pybind11Config.cmake.in

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2025-03-11 18:10:26 -04:00
dependabot[bot]
06e8ee2e35 chore(deps): bump actions/attest-build-provenance in the actions group (#5556)
Bumps the actions group with 1 update: [actions/attest-build-provenance](https://github.com/actions/attest-build-provenance).


Updates `actions/attest-build-provenance` from 2.2.2 to 2.2.3
- [Release notes](https://github.com/actions/attest-build-provenance/releases)
- [Changelog](https://github.com/actions/attest-build-provenance/blob/main/RELEASE.md)
- [Commits](bd77c07785...c074443f1a)

---
updated-dependencies:
- dependency-name: actions/attest-build-provenance
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-10 15:54:17 -04:00
dependabot[bot]
d422fda125 chore(deps): bump jinja2 from 3.1.5 to 3.1.6 in /docs (#5554)
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.5 to 3.1.6.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](https://github.com/pallets/jinja/compare/3.1.5...3.1.6)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-06 17:18:19 -05:00
pre-commit-ci[bot]
e24e300c75 chore(deps): update pre-commit hooks (#5547)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.9.4 → v0.9.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.4...v0.9.9)
- [github.com/pre-commit/mirrors-mypy: v1.14.1 → v1.15.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.14.1...v1.15.0)
- [github.com/python-jsonschema/check-jsonschema: 0.31.1 → 0.31.2](https://github.com/python-jsonschema/check-jsonschema/compare/0.31.1...0.31.2)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-06 14:22:10 -05:00
dependabot[bot]
a822be20d7 chore(deps): bump the actions group with 2 updates (#5546)
Bumps the actions group with 2 updates: [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) and [actions/attest-build-provenance](https://github.com/actions/attest-build-provenance).


Updates `pypa/cibuildwheel` from 2.22 to 2.23
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.22...v2.23)

Updates `actions/attest-build-provenance` from 2.2.0 to 2.2.2
- [Release notes](https://github.com/actions/attest-build-provenance/releases)
- [Changelog](https://github.com/actions/attest-build-provenance/blob/main/RELEASE.md)
- [Commits](520d128f16...bd77c07785)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
- dependency-name: actions/attest-build-provenance
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-06 14:21:54 -05:00
Dustin Spicuzza
ded70fe605 Add pkgconf-pypi entrypoint (#5552)
- This allows `pkgconf --cflags pybind11` and similar commands to work as expected
  if pkgconf is installed from pypi
2025-03-06 14:21:24 -05:00
Paul Ganssle
79be5c8316 test: Explicitly mark char as signed in dtype tests (#5545)
When run on a platform where `char` is unsigned by default — which is
implementation-defined.

This explicitly uses `signed char` in two tests where the sign of the
char is important (though only `test_dtype_normalized_num` fails without
this change).
2025-03-06 00:19:54 -08:00
Ralf W. Grosse-Kunstleve
2943a27a14 squash-merge smart_holder branch into master (#5542)
* Pure `git merge --squash smart_holder` (no manual interventions).

* Remove ubench/ directory.

* Remove include/pybind11/smart_holder.h

* [ci skip] smart_ptrs.rst updates [WIP/unfinished]

* [ci skip] smart_ptrs.rst updates continued; also updating classes.rst, advanced/classes.rst

* Remove README_smart_holder.rst

* Restore original README.rst from master

* [ci skip] Minimal change to README.rst, to leave a hint that this is pybind11v3

* [ci skip] Work in ChatGPT suggestions.

* Change macro name to PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE

* Add a note pointing to the holder reinterpret_cast.

* Incorporate suggestion by @virtuald: https://github.com/pybind/pybind11/pull/5542#discussion_r1967000989

* Systematically change most py::class_ to py::classh under docs/

* Remove references to README_smart_holder.rst

This should have been part of commit eb550d03d3.

* [ci skip] Fix minor oversight (``class_`` -> ``py::class_``) noticed by chance.

* [ci skip] Resolve suggestion by @virtuald

https://github.com/pybind/pybind11/pull/5542#discussion_r1969940605

* [ci skip] Apply suggestions by @timohl (thanks!)

* https://github.com/pybind/pybind11/pull/5542#discussion_r1970714551
* https://github.com/pybind/pybind11/pull/5542#discussion_r1971315329
* https://github.com/pybind/pybind11/pull/5542#discussion_r1971322821

* Replace `classh : class_` inhertance with `using`, as suggested by @henryiii

https://github.com/pybind/pybind11/pull/5542#issuecomment-2689034104

* Revert "Systematically change most py::class_ to py::classh under docs/"

This reverts commit ac9d31e13f.

* docs: focus on py::smart_holder instead of py::classh

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Restore minor general fixes that got lost when ac9d31e13f was reverted.

* Remove `- smart_holder` from list of branches in all .github/workflows

* Extend classh note to explain whitespace noise motivation.

* Suggest `py::smart_holder` for "most situations for safety"

* Add back PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT

This define was
* introduced with https://github.com/pybind/pybind11/pull/5286
* removed with https://github.com/pybind/pybind11/pull/5531

It is has been in use here:
* f02a2b7653/pybind11_protobuf/native_proto_caster.h (L89-L101)

Currently pybind11 unit tests for the two holder caster backwards compatibility traits

* `copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled`
* `move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled`

are missing.

* Add py::trampoline_self_life_support to all trampoline examples under docs/.

Address suggestion by @timohl:

* https://github.com/pybind/pybind11/pull/5542#issuecomment-2686452062

Add to the "please think twice" note: the overhead for safety is likely in the noise.

Also fix a two-fold inconsistency introduced by revert-commit 1e646c91b4:

1.

py::trampoline_self_life_support is mentioned in a note, but is missing in the example right before.

2.

The section starting with

    To enable safely passing a ``std::unique_ptr`` to a trampoline object between

is obsolete.

* Fix whitespace accident (indentation) introduced with 1e646c91b4

Apparently the mis-indentation was introduced when resolving merge conflicts for what became 1e646c91b4

* WHITESPACE CHANGES ONLY in README.rst (list of people that made significant contributions)

* Add Ethan Steinberg to list of people that made significant contributions (for completeness, unrelated to smart_holder work).

* [ci skip] Add to list of people that made significant contributions: major and/or influential contributors to smart_holder branch

* #2904 by @rhaschke was merged on Mar 16, 2021
* #3012 by @rhaschke was merged on May 28, 2021
* #3039 by @jakobandersen was merged on Jun 29, 2021
* #3048 by @Skylion007 was merged on Jun 18, 2021
* #3588 by @virtuald was merged on Jan 3, 2022
* #3633 by @wangxf123456 was merged on Jan 25, 2022
* #3635 by @virtuald was merged on Jan 26, 2022
* #3645 by @wangxf123456 was merged on Jan 25, 2022
* #3796 by @wangxf123456 was merged on Mar 10, 2022
* #3807 by @wangxf123456 was merged on Mar 18, 2022
* #3838 by @wangxf123456 was merged on Apr 15, 2022
* #3929 by @tomba was merged on May 7, 2022
* #4031 by @wangxf123456 was merged on Jun 27, 2022
* #4343 by @wangxf123456 was merged on Nov 18, 2022
* #4381 by @wangxf123456 was merged on Dec 5, 2022
* #4539 by @wangxf123456 was merged on Feb 28, 2023
* #4609 by @wangxf123456 was merged on Apr 6, 2023
* #4775 by @wangxf123456 was merged on Aug 3, 2023
* #4921 by @iwanders was merged on Nov 7, 2023
* #4924 by @iwanders was merged on Nov 6, 2023
* #5401 by @msimacek was merged on Oct 8, 2024

Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Dustin Spicuzza <dustin@virtualroadside.com>
Co-authored-by: Ivor Wanders <iwanders@users.noreply.github.com>
Co-authored-by: Jakob Lykke Andersen <Jakob@caput.dk>
Co-authored-by: Michael Šimáček <michael.simacek@oracle.com>
Co-authored-by: Robert Haschke <rhaschke@users.noreply.github.com>
Co-authored-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Co-authored-by: Xiaofei Wang <6218006+wangxf123456@users.noreply.github.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Co-authored-by: Dustin Spicuzza <dustin@virtualroadside.com>
Co-authored-by: Ivor Wanders <iwanders@users.noreply.github.com>
Co-authored-by: Jakob Lykke Andersen <Jakob@caput.dk>
Co-authored-by: Michael Šimáček <michael.simacek@oracle.com>
Co-authored-by: Robert Haschke <rhaschke@users.noreply.github.com>
Co-authored-by: Tomi Valkeinen <tomi.valkeinen@iki.fi>
Co-authored-by: Xiaofei Wang <6218006+wangxf123456@users.noreply.github.com>
2025-03-05 12:40:53 -08:00
Michał Górny
d8565ac731 Sync Py_TPFLAGS_MANAGED_DICT for PyPy3.11 across the codebase (#5537)
* Sync `Py_TPFLAGS_MANAGED_DICT` for PyPy3.11 across the codebase

Adjust the `Py_TPFLAGS_MANAGED_DICT` logic in `include/pybind11/attr.h`
to match the one used in `include/pybind11/detail/class.h`.

This is a followup to #5508.

* Use a common `#define` for pre-`Py_TPFLAGS_MANAGED_DICT` Pythons

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-02-20 16:53:45 -05:00
Matti Picus
09b9f44ab7 add recently released pypy3.11 (#5534) 2025-02-20 10:04:16 -08:00
gentlegiantJGC
73825f351b Improved reference_internal documentation (#5528)
* Improved reference_internal documentation

Improved the wording to make it easier to understand and added a note about the policy falling back to move if the return value is not an lvalue reference or pointer.

* Added bold and ticket number
2025-02-20 09:53:56 -08:00
Ralf W. Grosse-Kunstleve
b7c33009ac Start pybind11v3: Remove all code for PYBIND11_INTERNALS_VERSIONs 4 and 5 (#5530)
* Start pybind11v3

* Remove all code for PYBIND11_INTERNALS_VERSION 4 and 5

* Fix oversight: pybind11/_version.py needs to be updated as well.

* Add @pytest.mark.skipif("env.GRAALPY", reason="TODO debug segfault")
2025-02-19 09:24:02 -08:00
Michael Carlstrom
241524223a feat(types) Numpy.typing.NDArray (#5212)
* tests passing

* lint

* add comment

* remove empty tuple[()]

* test io_name

* style: pre-commit fixes

* remove accidental >

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* try T

* make both const_name

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* try and treat as string

* style: pre-commit fixes

* Update Numpy type hints

* style: pre-commit fixes

* re-run ci

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* re-run ci

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>

* remove escape characters

* Added tests for ArrayLike in signatures and fixed wrong types for Refs

---------

Signed-off-by: Michael Carlstrom <rmc@carlstrom.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tim Ohliger <ohliger.tim@gmail.com>
2025-02-17 23:13:05 -08:00
Ralf W. Grosse-Kunstleve
34a118fd36 Add release_gil_before_calling_cpp_dtor annotation for class_ (#5522)
* Backport of https://github.com/google/pybind11clif/pull/30088 (main PR) and https://github.com/google/pybind11clif/pull/30092 (minor fixes).

Note for completeness:

These are identical to the current versions on the pybind11clif main branch (@ commit 4841661df5daf26ecdedaace54e64d0782e63f64):

* test_class_release_gil_before_calling_cpp_dtor.cpp
* test_class_release_gil_before_calling_cpp_dtor.py

* Fix potential data race in test_class_release_gil_before_calling_cpp_dtor.cpp

The original intent was to let the singleton leak, but making that tread-safe is slightly more involved than this solution. It's totally fine in this case if the RegistryType destructor runs on process teardown.

See also: https://github.com/pybind/pybind11/pull/5522#issuecomment-2661068351

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2025-02-16 11:01:41 -08:00
Ralf W. Grosse-Kunstleve
c316cf3620 Make PYBIND11_INTERNALS_VERSION 6 the default on all platforms. (#5512) 2025-02-12 15:05:58 -08:00
daizhirui
31d7c870cf Remove some maybe-uninitialized warnings (#5516)
* Remove some maybe-uninitialized warnings

In the Eigen matrix type_caster, resize the matrix instead of assigning with a new one when the matrix size needs to be adjusted.

This can remove lots of compiling warnings about "maybe-uninitialized".

* Revert "Remove some maybe-uninitialized warnings"

This reverts commit 7d5a9b41aa.

* Suppress `-Wmaybe-uninitialized` warning

Reproducer: https://github.com/pybind/pybind11/pull/5516#issuecomment-2645846295

---------

Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-02-08 10:43:25 -08:00
pre-commit-ci[bot]
d2e7e8c687 chore(deps): update pre-commit hooks (#5513)
* chore(deps): update pre-commit hooks

updates:
- [github.com/pre-commit/mirrors-clang-format: v19.1.6 → v19.1.7](https://github.com/pre-commit/mirrors-clang-format/compare/v19.1.6...v19.1.7)
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.6...v0.9.4)
- [github.com/codespell-project/codespell: v2.3.0 → v2.4.1](https://github.com/codespell-project/codespell/compare/v2.3.0...v2.4.1)
- [github.com/PyCQA/pylint: v3.3.3 → v3.3.4](https://github.com/PyCQA/pylint/compare/v3.3.3...v3.3.4)
- [github.com/python-jsonschema/check-jsonschema: 0.30.0 → 0.31.1](https://github.com/python-jsonschema/check-jsonschema/compare/0.30.0...0.31.1)

* style: pre-commit fixes

* Rename `lins` to `lst` in test_pytypes.py to resolve codespell errors:

```
codespell................................................................Failed
- hook id: codespell
- exit code: 65

tests/test_pytypes.py:55: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:56: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:58: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:70: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:71: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:72: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:73: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:74: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:75: lins ==> lines, links, lions, loins, limns
tests/test_pytypes.py:76: lins ==> lines, links, lions, loins, limns
```

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
2025-02-04 08:36:08 -08:00
Michael Šimáček
ab44b307b2 Skip transient crash on GraalPy on OS X (#5514) 2025-02-04 07:48:47 -08:00
dependabot[bot]
8862cd4e7d chore(deps): bump seanmiddleditch/gha-setup-ninja in the actions group (#5509)
Bumps the actions group with 1 update: [seanmiddleditch/gha-setup-ninja](https://github.com/seanmiddleditch/gha-setup-ninja).


Updates `seanmiddleditch/gha-setup-ninja` from 5 to 6
- [Release notes](https://github.com/seanmiddleditch/gha-setup-ninja/releases)
- [Commits](https://github.com/seanmiddleditch/gha-setup-ninja/compare/v5...v6)

---
updated-dependencies:
- dependency-name: seanmiddleditch/gha-setup-ninja
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-02-02 21:54:30 -08:00
Matti Picus
fe87568f0b PyPy 3.11 does not implement Py_TPFLAGS_MANAGED_DICT (#5508)
* PyPy 3.11 does not implement Py_TPFLAGS_MANAGED_DICT

* add a comment (from review)

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-02-02 21:52:04 -08:00