1. 04 Aug, 2023 3 commits
  2. 03 Aug, 2023 1 commit
  3. 23 Jul, 2023 1 commit
    • Add command to check for vX.Y.Z tag vs pybind11/_version.py consistency. (#4757) · f3e06028
      * Add command to check for vX.Y.Z tag vs pybind11/_version.py consistency. Piggy-backing hints for converting changelog to release message.
      
      * Simpler way of double-checking version number in sources vs. git tag
      
      * Even simpler.
      
      * Fix rst rendering (hopefully) and remove stray dots.
      
      * [ci skip] Trying more to make GitHub rst renderer show this nicely.
      
      * [ci skip] Fix up RST rendering issues.
      
      Lesson learned:
      
      This is NOT GOOD:
      
      ```
      - Bullet nesting level 1.
          - Bullet nesting level 2.
      ```
      
      This is BETTER:
      
      ```
      - Bullet nesting level 1.
        - Bullet nesting level 2.
      ```
      
      Also consistently adding empty lines between bullet points, to make the .rst
      file easier to read.
      
      Also piggy-backing a few very minor enhancements.
      Ralf W. Grosse-Kunstleve committed
  4. 17 Jul, 2023 2 commits
  5. 15 Jul, 2023 2 commits
  6. 14 Jul, 2023 2 commits
  7. 12 Jul, 2023 4 commits
  8. 11 Jul, 2023 1 commit
  9. 10 Jul, 2023 1 commit
  10. 09 Jul, 2023 1 commit
  11. 04 Jul, 2023 1 commit
  12. 27 Jun, 2023 1 commit
  13. 24 Jun, 2023 1 commit
  14. 21 Jun, 2023 1 commit
  15. 17 Jun, 2023 1 commit
  16. 16 Jun, 2023 1 commit
  17. 10 Jun, 2023 1 commit
  18. 07 Jun, 2023 3 commits
  19. 25 May, 2023 1 commit
    • Use annotated for array (#4679) · d0232b11
      * use Annotated for std::array docstring
      
      * add tests
      
      * fix test
      
      * style: pre-commit fixes
      
      * fix valarray annotation
      
      * style: pre-commit fixes
      
      * refix test
      
      * add FixedSize
      
      * style: pre-commit fixes
      
      * Update test_stl.py
      
      * style: pre-commit fixes
      
      ---------
      
      Co-authored-by: Taiju Yamada <taiju.yamada@mujin.co.jp>
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      T.Yamada committed
  20. 23 May, 2023 3 commits
    • Add `format_descriptor<>` & `npy_format_descriptor<>` `PyObject *` specializations. (#4674) · 8e1f9d5c
      * Add `npy_format_descriptor<PyObject *>` to enable `py::array_t<PyObject *>` to/from-python conversions.
      
      * resolve clang-tidy warning
      
      * Use existing constructor instead of adding a static method. Thanks @Skylion007 for pointing out.
      
      * Add `format_descriptor<PyObject *>`
      
      Trivial addition, but still in search for a meaningful test.
      
      * Add test_format_descriptor_format
      
      * Ensure the Eigen `type_caster`s do not segfault when loading arrays with dtype=object
      
      * Use `static_assert()` `!std::is_pointer<>` to replace runtime guards.
      
      * Add comments to explain how to check for ref-count bugs. (NO code changes.)
      
      * Make the "Pointer types ... are not supported" message Eigen-specific, as suggested by @Lalaland. Move to new pybind11/eigen/common.h header.
      
      * Change "format_descriptor_format" implementation as suggested by @Lalaland. Additional tests meant to ensure consistency between py::format_descriptor<>, np.array, np.format_parser turn out to be useful only to highlight long-standing inconsistencies.
      
      * resolve clang-tidy warning
      
      * Account for np.float128, np.complex256 not being available on Windows, in a future-proof way.
      
      * Fully address i|q|l ambiguity (hopefully).
      
      * Remove the new `np.format_parser()`-based test, it's much more distracting than useful.
      
      * Use bi.itemsize to disambiguate "l" or "L"
      
      * Use `py::detail::compare_buffer_info<T>::compare()` to validate the `format_descriptor<T>::format()` strings.
      
      * Add `buffer_info::compare<T>` to make `detail::compare_buffer_info<T>::compare` more visible & accessible.
      
      * silence clang-tidy warning
      
      * pytest-compatible access to np.float128, np.complex256
      
      * Revert "pytest-compatible access to np.float128, np.complex256"
      
      This reverts commit e9a289c50fc07199806d14ded644215ab6f03afa.
      
      * Use `sizeof(long double) == sizeof(double)` instead of `std::is_same<>`
      
      * Report skipped `long double` tests.
      
      * Change the name of the new `buffer_info` member function to `item_type_is_equivalent_to`. Add comment defining "equivalent" by example.
      
      * Change `item_type_is_equivalent_to<>()` from `static` function to member function, as suggested by @Lalaland
      Ralf W. Grosse-Kunstleve committed
    • Create s Security Policy (#4671) · 6e6bcca5
      * Create SECURITY.md
      
      * Update test_files.py to include SECURITY.md file
      
      * Update MANIFEST.in to include SECURITY.md file
      Joyce committed
    • Python 3.11+: Add `__notes__` to `error_already_set::what()` output. (#4678) · ce9bbc0a
      * First version adding `__notes__` to `error_already_set::what()` output.
      
      * Fix trivial oversight (missing adjustment in existing test).
      
      * Minor enhancements of new code.
      
      * Re-enable `cmake --target cpptest -j 2`
      
      * Revert "Re-enable `cmake --target cpptest -j 2`"
      
      This reverts commit 60816285e9e7b95b7d33a60805888b80b2bec641.
      
      * Add general comment explaining why the `error_fetch_and_normalize` code is so unusual.
      Ralf W. Grosse-Kunstleve committed
  21. 22 May, 2023 1 commit
    • chore: update changelog, with target date for v2.11.0 release (#4677) · 19816f0d
      * Remove .dev1 from version number.
      
      * [skip ci] Update changelog.rst
      
      * [ci skip] Fix pre-commit: rst ``code`` is two backticks
      
      * Apply fix suggested by @henryiii
      
      * [ci skip] Set target date for the release to June 2, 2023
      
      * [ci skip] Apply more fixes suggested by @henryiii (I missed those before).
      
      * [ci skip] Revert "Remove .dev1 from version number."
      
      This reverts commit afc80134cb1035be2913fd8153a16a864181c52c.
      Ralf W. Grosse-Kunstleve committed
  22. 15 May, 2023 1 commit
    • ci: set minimal permissions to github workflows (#4665) · d72ffb44
      * set ci.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * set configure.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * set format.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * set pip.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * set upstream.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * set labeler.yml minimal permissions
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * Update ci.yml to read all
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * test labeler.yml
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      * restore the if at labeler.yml
      
      Signed-off-by: Joyce <joycebrum@google.com>
      
      ---------
      
      Signed-off-by: Joyce <joycebrum@google.com>
      Joyce committed
  23. 09 May, 2023 1 commit
    • Update errors in string "Explicit conversions" docs (#4658) · cca4c51c
      `PyUnicode_DecodeLatin1` requires you to pass in the `error`
      parameter. The code as it is in the docs didn't compile.
      
      There is a reference leak in the example
      code. `PyUnicode_DecodeLatin1` returns a new reference. Calling
      `py::str(PyObject*)` calls `PyObject_Str`, which also returns a new
      reference. That reference is managed by the `py::str`
      constructor (which correctly steals the reference, using the
      `stolen_t` constructor), but the original reference returned by
      `PyUnicode_DecodeLatin1` is never decref'd: it never makes it into an
      `object`, and it's never manually decremented.
      
      This fixes both of those issues. The code compiles, and I viewed the
      sphinx docs locally.
      Tim Stumbaugh committed
  24. 08 May, 2023 1 commit
    • Elide to-python conversion of setter return values (#4621) · e9b961d9
      * Reproducer for property setter with return type that is not wrapped.
      
      * Use `py::class_<OptionsBase>()` to work around the return value conversion issue.
      
      * WIP drop_return_value
      
      * Remove struct drop_return_value
      
      * Introduce `return_value_policy::return_none` for use by setters.
      
      * Add `is_setter` to attr.h and use from `.def_property()`
      
      * Merge the new test into test_methods_and_attributes
      
      * Remove return_none return_value_policy again.
      
      * Fix oversight (NOLINTNEXTLINE placement).
      
      * Simplification (for the better) found while searching for a way to resolve GCC build failures.
      
      Example of failure resolved by this change:
      
      g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
      
      ```
      cd /build/tests && /usr/bin/c++ -DPYBIND11_TEST_EIGEN -Dpybind11_tests_EXPORTS -I/mounted_pybind11/include -isystem /usr/include/python3.8 -isystem /build/_deps/eigen-src -g -std=c++17 -fPIC -fvisibility=hidden -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -MD -MT tests/CMakeFiles/pybind11_tests.dir/test_buffers.cpp.o -MF CMakeFiles/pybind11_tests.dir/test_buffers.cpp.o.d -o CMakeFiles/pybind11_tests.dir/test_buffers.cpp.o -c /mounted_pybind11/tests/test_buffers.cpp
      In file included from /mounted_pybind11/include/pybind11/stl.h:12,
                       from /mounted_pybind11/tests/test_buffers.cpp:10:
      /mounted_pybind11/include/pybind11/pybind11.h: In instantiation of ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def_property(const char*, const Getter&, const Setter&, const Extra& ...) [with Getter = pybind11::cpp_function; Setter = std::nullptr_t; Extra = {pybind11::return_value_policy}; type_ = pybind11::buffer_info; options = {}]’:
      /mounted_pybind11/include/pybind11/pybind11.h:1716:58:   required from ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def_property_readonly(const char*, const pybind11::cpp_function&, const Extra& ...) [with Extra = {pybind11::return_value_policy}; type_ = pybind11::buffer_info; options = {}]’
      /mounted_pybind11/include/pybind11/pybind11.h:1684:9:   required from ‘pybind11::class_<type_, options>& pybind11::class_<type_, options>::def_readonly(const char*, const D C::*, const Extra& ...) [with C = pybind11::buffer_info; D = long int; Extra = {}; type_ = pybind11::buffer_info; options = {}]’
      /mounted_pybind11/tests/test_buffers.cpp:209:61:   required from here
      /mounted_pybind11/include/pybind11/pybind11.h:1740:25: error: call of overloaded ‘cpp_function(std::nullptr_t&, pybind11::is_setter)’ is ambiguous
       1740 |             name, fget, cpp_function(method_adaptor<type>(fset), is_setter()), extra...);
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /mounted_pybind11/include/pybind11/pybind11.h:101:5: note: candidate: ‘pybind11::cpp_function::cpp_function(Func&&, const Extra& ...) [with Func = std::nullptr_t&; Extra = {pybind11::is_setter}; <template-parameter-1-3> = void]’
        101 |     cpp_function(Func &&f, const Extra &...extra) {
            |     ^~~~~~~~~~~~
      In file included from /mounted_pybind11/include/pybind11/stl.h:12,
                       from /mounted_pybind11/tests/test_buffers.cpp:10:
      /mounted_pybind11/include/pybind11/pybind11.h:87:5: note: candidate: ‘pybind11::cpp_function::cpp_function(std::nullptr_t, const Extra& ...) [with Extra = {pybind11::is_setter}; std::nullptr_t = std::nullptr_t]’
         87 |     cpp_function(std::nullptr_t, const Extra &...) {}
            |     ^~~~~~~~~~~~
      ```
      
      * Bug fix: obvious in hindsight. I thought the original version was incrementing the reference count for None, but no.
      
      Discovered via many failing tests in the wild (10s of thousands).
      
      It is very tricky to construct a meaningful unit test for this bug specifically. It's unlikely to come back, because 10s of thousands of tests will fail again.
      Ralf W. Grosse-Kunstleve committed
  25. 07 May, 2023 1 commit
    • Add `type_caster<PyObject>` (#4601) · 90312a6e
      * Add `type_caster<PyObject>` (tests are still incomplete).
      
      * Fix oversight (`const PyObject *`).
      
      * Ensure `type_caster<PyObject>` only works for `PyObject *`
      
      * Move `is_same_ignoring_cvref` into `detail` namespace.
      
      * Add test_cast_nullptr
      
      * Change is_same_ignoring_cvref from variable template to using.
      
      ```
      test_type_caster_pyobject_ptr.cpp:8:23: error: variable templates only available with ‘-std=c++14’ or ‘-std=gnu++14’ [-Werror]
          8 | static constexpr bool is_same_ignoring_cvref = std::is_same<detail::remove_cvref_t<T>, U>::value;
            |                       ^~~~~~~~~~~~~~~~~~~~~~
      ```
      
      * Remove `return_value_policy::reference_internal` `keep_alive` feature (because of doubts about it actually being useful).
      
      * Add missing test, fix bug (missing `throw error_already_set();`), various cosmetic changes.
      
      * Move `type_caster<PyObject>` from test to new include (pybind11/type_caster_pyobject_ptr.h)
      
      * Add new header file to CMakeLists.txt and tests/extra_python_package/test_files.py
      
      * Backport changes from https://github.com/google/pywrapcc/pull/30021 to https://github.com/pybind/pybind11/pull/4601
      
      * Fix oversight in test (to resolve a valgrind leak detection error) and add a related comment in cast.h.
      
      No production code changes.
      
      Make tests more sensitive by using `ValueHolder` instead of empty tuples and dicts.
      
      Manual leak checks with `while True:` & top command repeated for all tests.
      
      * Add tests for interop with stl.h `list_caster`
      
      (No production code changes.)
      
      * Bug fix in test. Minor comment enhancements.
      
      * Change `type_caster<PyObject>::name` to `object`, as suggested by @Skylion007
      
      * Expand comment for the new `T cast(const handle &handle)` [`T` = `PyObject *`]
      
      * Add `T cast(object &&obj)` overload as suggested by @Skylion007
      
      The original suggestion leads to `error: call to 'cast' is ambiguous` (full error message below), therefore SFINAE guarding is needed.
      
      ```
      clang++ -o pybind11/tests/test_type_caster_pyobject_ptr.os -c -std=c++17 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -isystem /usr/include/python3.10 -isystem /usr/include/eigen3 -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/usr/local/google/home/rwgk/forked/pybind11/include -I/usr/local/google/home/rwgk/clone/pybind11/include /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp
      In file included from /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:1:
      In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:12:
      In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:13:
      In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/detail/class.h:12:
      In file included from /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/attr.h:14:
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1165:12: error: call to 'cast' is ambiguous
          return pybind11::cast<T>(std::move(*this));
                 ^~~~~~~~~~~~~~~~~
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:109:70: note: in instantiation of function template specialization 'pybind11::object::cast<_object *>' requested here
                      return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
                                                                           ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/functional.h:103:16: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load(pybind11::handle, bool)::func_wrapper::operator()' requested here
              struct func_wrapper {
                     ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1456:47: note: in instantiation of member function 'pybind11::detail::type_caster<std::function<_object *(int)>>::load' requested here
              if ((... || !std::get<Is>(argcasters).load(call.args[Is], call.args_convert[Is]))) {
                                                    ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1434:50: note: in instantiation of function template specialization 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_impl_sequence<0UL, 1UL>' requested here
          bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); }
                                                       ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:227:33: note: in instantiation of member function 'pybind11::detail::argument_loader<const std::function<_object *(int)> &, int>::load_args' requested here
                  if (!args_converter.load_args(call)) {
                                      ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:101:9: note: in instantiation of function template specialization 'pybind11::cpp_function::initialize<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), _object *, const std::function<_object *(int)> &, int, pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy>' requested here
              initialize(
              ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/pybind11.h:1163:22: note: in instantiation of function template specialization 'pybind11::cpp_function::cpp_function<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::name, pybind11::scope, pybind11::sibling, pybind11::return_value_policy, void>' requested here
              cpp_function func(std::forward<Func>(f),
                           ^
      /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:48:7: note: in instantiation of function template specialization 'pybind11::module_::def<(lambda at /usr/local/google/home/rwgk/forked/pybind11/tests/test_type_caster_pyobject_ptr.cpp:50:9), pybind11::return_value_policy>' requested here
          m.def(
            ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1077:3: note: candidate function [with T = _object *, $1 = 0]
      T cast(object &&obj) {
        ^
      /usr/local/google/home/rwgk/forked/pybind11/include/pybind11/cast.h:1149:1: note: candidate function [with T = _object *]
      cast(object &&object) {
      ^
      1 error generated.
      ```
      Ralf W. Grosse-Kunstleve committed
  26. 05 May, 2023 1 commit
    • Introduce recursive_container_traits (#4623) · f7016546
      * Testing
      
      * Similar fix for std::vector
      
      * Fix infinite recursion check:
      
      1) Apply to is_copy_assignable additionally
      2) Check infinite recursion for map-like types
      
      * style: pre-commit fixes
      
      * Optional commit that demonstrates the limitations of this PR
      
      * Fix positioning of container bindings
      
      The bindings were previously in a block that was only activated if numpy
      was available.
      
      * Suggestions from code review: API side
      
      * Suggestions from code review: Test side
      
      * Suggestions from code review
      
      1) Renaming: is_recursive_container and
         MutuallyRecursiveContainerPair(MV|VM)
      2) Avoid ambiguous specializations of is_recursive_container
      
      * Some little fixes
      
      * Reordering of structs
      
      * Add recursive checks for is_move_constructible
      
      * Static testing for pybind11 type traits
      
      * More precise checking of recursive types
      
      Instead of a trait `is_recursive_container`, use a trait
      `recursive_container_traits` with dependent type
      `recursive_container_traits::type_to_check_recursively`.
      So, instead of just checking if a type is recursive and then trying to
      somehow deal with it, recursively-defined traits such as
      is_move_constructible can now directly ask this trait where the
      recursion should proceed.
      
      * Review suggestions
      
      1. Use std::conditional
      2. Fix typo
      
      * Remove leftover include from test
      
      ---------
      
      Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
      Franz Pöschel committed
  27. 03 May, 2023 2 commits