1. 13 Sep, 2024 3 commits
    • Increment `PYBIND11_VERSION_PATCH` · 2e081527
      QA:
      
      ```
      $ nox -s tests_packaging
      nox > Running session tests_packaging
      nox > Creating virtual environment (virtualenv) using python3 in .nox/tests_packaging
      nox > python -m pip install -r tests/requirements.txt
      nox > pytest tests/extra_python_package
      =========================================================== test session starts ============================================================
      platform darwin -- Python 3.10.2, pytest-7.4.4, pluggy-1.5.0
      rootdir: /Users/rgrossekunst/forked/pybind11/tests/extra_python_package
      configfile: pytest.ini
      plugins: timeout-2.3.1
      collected 4 items
      
      tests/extra_python_package/test_files.py ....                                                                                        [100%]
      
      ============================================================ 4 passed in 22.82s ============================================================
      nox > Session tests_packaging was successful.
      ```
      Ralf W. Grosse-Kunstleve committed
    • [v2.12] Backport: Enable type-safe interoperability between different… · b58436af
      [v2.12] Backport: Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5368)
      
      * Enable type-safe interoperability between different independent Python/C++ bindings systems. (#5296)
      
      * `self.__cpp_transporter__()` proof of concept: Enable passing C++ pointers across extensions even if the `PYBIND11_INTERNALS_VERSION`s do not match.
      
      * Include cleanup (mainly to resolve PyPy build failures).
      
      * Fix clang-tidy errors.
      
      * Resolve `error: extra
      
      * factor out platform_abi_id.h from internals.h (no functional changes)
      
      * factor out internals_version.h from internals.h (no functional changes)
      
      * Update CMakeLists.txt, tests/extra_python_package/test_files.py
      
      * Revert "factor out internals_version.h from internals.h (no functional changes)"
      
      This reverts commit 3ccea8cd4302cfaf2b6842f77ee3a2eefd61182a.
      
      * Remove internals_version.h from CMakeLists.txt, tests/extra_python_package/test_files.py
      
      * `.__cpp_transporter__()` implementation: compare `pybind11_platform_abi_id`, `cpp_typeid_name`
      
      * Add PremiumTraveler
      
      * Rename test_cpp_transporter_traveler_type.h -> test_cpp_transporter_traveler_types.h
      
      * Expand tests: `PremiumTraveler`, `get_points()`
      
      * Shuffle order of tests (no real changes).
      
      * Move `__cpp_transporter__` lambda to `py::cpp_transporter()` regular function.
      
      * Use `type_caster_generic::load(self)` instead of `cast<T *>(self)`
      
      * Pass `const std::type_info *` via `py::capsule` (instead of `cpp_typeid_name`).
      
      * Make platform_abi_id.h completely stand-alone.
      
      * rename exo_planet.cpp -> exo_planet_pybind11.cpp
      
      * Add exo_planet_c_api.cpp (incomplete).
      
      * Fix silly oversight (wrong filename in `#include`).
      
      * Resolve clang-tidy errors:
      
      ```
      /__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:10:18: error: 'wrapGetLuggage' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
         10 | static PyObject *wrapGetLuggage(PyObject *, PyObject *) { return PyUnicode_FromString("TODO"); }
            | ~~~~~~           ^
      /__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:14:20: error: 'ThisMethodDef' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
         14 | static PyMethodDef ThisMethodDef[]
            | ~~~~~~             ^
      /__w/pybind11/pybind11/tests/exo_planet_c_api.cpp:17:27: error: 'ThisModuleDef' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace,-warnings-as-errors]
         17 | static struct PyModuleDef ThisModuleDef = {
            | ~~~~~~                    ^
      ```
      
      * Implement exo_planet_c_api GetLuggage(), GetPoints()
      
      * Move new code from test_cpp_transporter_traveler_bindings.h to pybind11/detail/type_caster_base.h, under the name `class_dunder_cpp_transporter()`
      
      * Fix oversight.
      
      * Unconditionally add `__cpp_transporter__` method to all `py::class_` objects, but do not include that magic method in docstring signatures.
      
      * Back out pybind11/detail/platform_abi_id.h for now. Maximizing reusability can be handled separately, later.
      
      * Small cleanup.
      
      * Restore and add to `test_call_cpp_transporter_*()`
      
      * Ensure https://github.com/pybind/pybind11/issues/3788 does not bite again.
      
      * `class_dunder_cpp_transporter()`: replace `obj.cast<std::string>()` with `std::string(obj)`
      
      * Add (simple) copyright notices in all newly added files.
      
      * Globally replace cpp_transporter with cpp_conduit
      
      * style: pre-commit fixes
      
      * IWYU fixes
      
      * Rename `class_dunder_cpp_conduit()` -> `cpp_conduit_method()`
      
      * Change `pybind11_platform_abi_id`, `pointer_kind` argument types from `str` to `bytes`.
      
      This avoids the unicode decode/encode roundtrips:
      
      * More robust (no decode/encode errors).
      
      * Minor runtime optimization.
      
      * Systematically rename `cap_cpp_type_info` -> `cpp_type_info_capsule` (no functional changes).
      
      * Systematically replace `cpp_type_info_capsule` `name`: `"const std::type_info *"` -> `typeid(std::type_info).name()` (this IS a functional change).
      
      This provides an extra layer of protection against C++ ABI mismatches:
      
      * The first and most important layer is that the `PYBIND11_PLATFORM_ABI_ID`s must match between extensions.
      
      * The second layer is that the `typeid(std::type_info).name()`s must match between extensions.
      
      * Fix sort order accident in tests/CMakeLists.txt
      
      * Apply suggestions from code review
      
      Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
      
      * style: pre-commit fixes
      
      * refactor: rename to _pybind_conduit_v1_
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Add test_home_planet_wrap_very_lonely_traveler(), test_exo_planet_pybind11_wrap_very_lonely_traveler()
      
      * Resolve clang-tidy errors:
      
      ```
      /__w/pybind11/pybind11/tests/test_cpp_conduit_traveler_bindings.h:39:32: error: parameter 'm' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param,-warnings-as-errors]
         10 |     py::class_<LonelyTraveler>(m, "LonelyTraveler");
            |                                ^
            |                                std::move( )
      /__w/pybind11/pybind11/tests/test_cpp_conduit_traveler_bindings.h:43:52: error: parameter 'm' is passed by value and only copied once; consider moving it to avoid unnecessary copies [performance-unnecessary-value-param,-warnings-as-errors]
         43 |     py::class_<VeryLonelyTraveler, LonelyTraveler>(m, "VeryLonelyTraveler");
            |                                                    ^
            |                                                    std::move( )
      ```
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
      
      * Remove `from __future__ import annotations`
      
      * Update Changelog
      
      * Increment patch version number (v2.12.1)
      
      * Revert "Increment patch version number (v2.12.1)"
      
      This reverts commit 0999c2784b007c76a70e239b5079c965dbbe2a64.
      
      * Revert "Update Changelog"
      
      This reverts commit 166ba04703e3393661ad995041a1eb7f9e342cb8.
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
      Ralf W. Grosse-Kunstleve committed
  2. 27 Mar, 2024 4 commits
  3. 26 Mar, 2024 2 commits
    • feat: make `numpy.h` compatible with both NumPy 1.x and 2.x (#5050) · 705efcce
      * API: Make `numpy.h` compatible with both NumPy 1.x and 2.x
      
      * TST: Update numpy dtype flags test to not covert flags to char
      
      * API: Add `numpy2.h` instead and make `numpy.h` safe
      
      This means that users of `numpy.h` cannot be broken, but need to
      update to `numpy2.h` if they want to compile for NumPy 2.
      
      Using Macros simply and didn't bother to try to remove unnecessary
      code paths.
      
      * API: Rather than `numpy2.h` use a define for the user.
      
      * Thread `PYBIND11_NUMPY2_SUPPORT` through things and try to adept test matrix
      
      * Small fixups (shouldn't matter)?
      
      * Fixup.  Does upgrading scipy help?  (it shouldn't?)
      
      (Some other small fixup)
      
      * Use NumPy 2 nightlies for ubuntu-latest job also
      
      * BUG: Fix numpy.bool check
      
      * TST: Fix complexwarning
      
      * BUG: Fix the fact that only the 50 slot is filled with the copy alias
      
      (There were 3 functions all doing the same, only this slot survived 2.x)
      
      * TST: One more test tweak
      
      * TST: Use "long" name for long, since it changed on windows
      
      * TST: Apparently we didn't always have ulong, so just use `L`
      
      * TST: Enforce dtype='l' for test as default isn't long anymore on windows
      
      * Rename macro and invert logic to PYBIND11_NUMPY_1_ONLY
      
      * PYBIND11_INTERNAL_NUMPY_1_ONLY_DETECTED
      
      * Test and code comment expansion
      
      * CI: Use pre-releases of numpy/scipy from pip via explicit version
      
      * CI: NumPy 2 only available on almalinux (as it is Python >=3.9)
      
      * MAINT: Match name more exactly and adopt error phrasing
      
      * MAINT: Pushed early, move helper to be private member
      
      * fix error message compilation when using NumPy 1.x-only backcompat
      
      * silence name shadowing warning
      
      * chore: minor optimization
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
      Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
      Sebastian Berg committed
    • tests: hide warning on clang (#5069) · e0f2c715
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Henry Schreiner committed
  4. 21 Mar, 2024 3 commits
  5. 14 Feb, 2024 1 commit
  6. 13 Feb, 2024 2 commits
  7. 06 Feb, 2024 1 commit
  8. 28 Jan, 2024 1 commit
    • doc: add litgen to the automatic generators list (compiling.rst) (#5012) · 768cebe1
      * doc: add litgen to the automatic generators list (compiling.rst)
      
      Added this:
      
      [litgen]_ is an automatic python bindings generator with a focus on generating
      documented and discoverable bindings: bindings will nicely reproduce the documentation
      found in headers. It is is based on srcML (srcml.org), a highly scalable, multi-language
      parsing tool with a developer centric approach. The API that you want to expose to python
      must be C++14 compatible (but your implementation can use more modern constructs).
      
      .. [litgen] https://pthom.github.io/litgen
      
      * style: pre-commit fixes
      
      ---------
      
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Pascal Thomet committed
  9. 17 Jan, 2024 1 commit
  10. 13 Jan, 2024 2 commits
  11. 08 Jan, 2024 1 commit
  12. 02 Jan, 2024 2 commits
  13. 30 Dec, 2023 1 commit
  14. 15 Dec, 2023 3 commits
  15. 14 Dec, 2023 2 commits
    • fix(cmake): upgrade maximum supported CMake version to 3.27 (#4786) · daea1130
      * Upgrade maximum supported CMake version to 3.27 to fix warning with CMP0148 policy (#4785)
      
      * Update `macos_brew_install_llvm` pipeline to use expected Python installation
      
      * Fix `Python_EXECUTABLE` Cmake variable typo
      
      * Apply suggestions from code review
      
      * fix: use FindPython for CMake 3.18+ by default for pybind11's tests
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * tests: fix issues with finding Python
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * tests: also set executable on subdir tests
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * fix(cmake): correct logic for FindPython
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Update ci.yml
      
      * Revert "Update ci.yml"
      
      This reverts commit 33798adf3f3892ac4b78da8d3d91d3b27611bbe5.
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
      Pol Mesalles committed
    • fix: make_static_property_type() (#4971) · 7d538a42
      Update make_static_property_type() to make it compatible with Python
      3.13: set Py_TPFLAGS_MANAGED_DICT flag before calling PyType_Ready().
      Victor Stinner committed
  16. 07 Dec, 2023 1 commit
  17. 05 Dec, 2023 1 commit
  18. 29 Nov, 2023 1 commit
  19. 27 Nov, 2023 1 commit
  20. 16 Nov, 2023 4 commits
    • pybind11.pc: use pcfiledir for relative destinations (#4830) · dc9b3959
      * pybind11.pc: use pcfiledir for relative destinations
      
      If the datarootdir is absolute, just use the absolute path directly.
      However, if it is relative, we can compute the prefix from the location
      of the `.pc` file itself. This allows the install to be relocatable.
      
      * chore: use 3.20's cmake_path if available
      
      * style: pre-commit fixes
      
      * Update CMakeLists.txt
      
      ---------
      
      Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Ben Boeckel committed
    • fix(cmake): findpython issues and 3.12 support for pybind11_find_import (#4941) · 9591cfb0
      * fix(cmake): findpython issues and 3.12 support for pybind11_find_import
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Update pybind11NewTools.cmake
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Henry Schreiner committed
    • ci: add more versions of numpy/scipy/pypy (#4714) · 6831666f
      * ci: add more versions of numpy/scipy/pypy
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Apply suggestions from code review
      
      * style: pre-commit fixes
      
      * Update requirements.txt
      
      * Update requirements.txt
      
      * Apply suggestions from code review
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Henry Schreiner committed
    • fix(cmake): avoid really slow compile on emscripten (#4642) · 6cf90e72
      * fix: avoid really slow compile on emscripten
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      
      * Update tools/pybind11Common.cmake
      
      ---------
      
      Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
      Henry Schreiner committed
  21. 15 Nov, 2023 1 commit
  22. 08 Nov, 2023 2 commits
    • Fix a long-standing bug in the handling of Python multiple inheritance (#4762) · e250155a
      * Equivalent of https://github.com/google/clif/commit/5718e4d0807fd3b6a8187dde140069120b81ecef
      
      * Resolve clang-tidy errors.
      
      * Moving test_PPCCInit() first changes the behavior!
      
      * Resolve new Clang dev C++11 errors:
      
      ```
      The CXX compiler identification is Clang 17.0.0
      ```
      
      ```
      pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
      ```
      
      ```
      cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
      ```
      
      * Resolve gcc 4.8.5 error:
      
      ```
      pytypes.h:1615:12: error: missing space between '""' and suffix identifier
      ```
      
      * Specifically exclude `__clang__`
      
      * Snapshot of debugging code (does NOT pass pre-commit checks).
      
      * Revert "Snapshot of debugging code (does NOT pass pre-commit checks)."
      
      This reverts commit 1d4f9ff2632b32ddcb0dc7ecd0ab7a4ce4c15a4e.
      
      * [ci skip] Order Dependence Demo
      
      * Revert "[ci skip] Order Dependence Demo"
      
      This reverts commit d37b5409d4e5b835620ccbb321a4e1ba89af315c.
      
      * One way to deal with the order dependency issue. This is not the best way, more like a proof of concept.
      
      * Move test_PC() first again.
      
      * Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()`
      
      * Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept."
      
      This reverts commit eb09c6c1b978208ceee40f05bbe75491b6ff8ad6.
      
      * clang-tidy fixes (automatic)
      
      * Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed.
      
      * Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152
      
      The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked,
      which was actually found in the wild: the mock returned `None` for `self`.
      This was inconsequential because `inst` is currently cast straight back to
      `PyObject *` to compute `all_type_info()`, which is empty if `self` is not
      a pybind11 `instance`, and then `inst` is never dereferenced. However, the
      unsafe detour through `instance *` is easily avoided and the updated
      implementation is less prone to accidents while debugging or refactoring.
      
      * Fix actual undefined behavior exposed by previous changes.
      
      It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:
      
      https://github.com/pybind/pybind11/blob/f3e0602802c7840992c97f4960515777cad6a5c7/include/pybind11/detail/type_caster_base.h#L262-L263
      
      ```
      259     // Main constructor for a found value/holder:
      260     value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index)
      261         : inst{i}, index{index}, type{type},
      262           vh{inst->simple_layout ? inst->simple_value_holder
      263                                  : &inst->nonsimple.values_and_holders[vpos]} {}
      ```
      
      * Add test_mock_new()
      
      * Experiment: specify indirect bases
      
      * Revert "Experiment: specify indirect bases"
      
      This reverts commit 4f90d85f9fc15290d6be54d5ae9417bd131b84d9.
      
      * Add `all_type_info_check_for_divergence()` and some tests.
      
      * Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`
      
      * Resolve clang-tidy error:
      
      ```
      include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors]
                      if (matching_bases.size() != 0) {
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
                          !matching_bases.empty()
      ```
      
      * Revert "Resolve clang-tidy error:"
      
      This reverts commit df27188dc6d6cf333145755543f56b2f6657aa5e.
      
      * Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`"
      
      This reverts commit 5f5fd6a68e3cff1726628f6dea8e1c0754636a23.
      
      * Revert "Add `all_type_info_check_for_divergence()` and some tests."
      
      This reverts commit 0a9599f775bfd3ca196c5e23a3fcf2890cbf6e82.
      Ralf W. Grosse-Kunstleve committed