pybind11/tests
Ralf W. Grosse-Kunstleve e9b961d9b9
Elide to-python conversion of setter return values (#4621)
* 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.
2023-05-08 10:13:54 -07:00
..
extra_python_package Add `type_caster<PyObject>` (#4601) 2023-05-07 10:15:53 -07:00
extra_setuptools chore: drop Python 3.5 (#3719) 2022-02-11 19:06:16 -05:00
test_cmake_build chore: drop Python 3.5 (#3719) 2022-02-11 19:06:16 -05:00
test_embed Introduce `get_python_state_dict()` for Python 3.12 compatibility. (#4570) 2023-03-27 17:52:57 -07:00
CMakeLists.txt Add `type_caster<PyObject>` (#4601) 2023-05-07 10:15:53 -07:00
conftest.py Change `always_forkserver_on_unix()` to `use_multiprocessing_forkserver_on_linux()` (#4577) 2023-03-16 14:33:34 -07:00
constructor_stats.h test: ConstructorStats newline (PyPy) (#4167) 2022-08-29 23:25:01 -04:00
cross_module_gil_utils.cpp Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` option (cmake, C++ define) (#4216) 2022-10-30 08:57:23 -07:00
cross_module_interleaved_error_already_set.cpp Add `error_scope` to `detail::get_internals()` (#3981) 2022-05-31 11:51:13 -07:00
eigen_tensor_avoid_stl_array.cpp Fix ODR violations in our Eigen Tensor tests (#4412) 2022-12-20 05:34:00 -08:00
env.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
local_bindings.h Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
object.h Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
pybind11_cross_module_tests.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
pybind11_tests.cpp Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` option (cmake, C++ define) (#4216) 2022-10-30 08:57:23 -07:00
pybind11_tests.h Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
pytest.ini chore: drop Python 3.5 (#3719) 2022-02-11 19:06:16 -05:00
requirements.txt Fix: 3.11 beta support (#3923) 2022-07-06 16:35:12 -04:00
test_async.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_async.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_buffers.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_buffers.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_builtin_casters.cpp Introduce a new style of warning suppression based on push/pop (#4285) 2022-11-28 07:39:38 -08:00
test_builtin_casters.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_call_policies.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_call_policies.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_callbacks.cpp Fix functional.h bug + introduce test to verify that it is fixed (#4254) 2022-11-02 11:32:53 -07:00
test_callbacks.py Always display python type information in cast errors (#4463) 2023-02-09 21:21:17 -08:00
test_chrono.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_chrono.py chore: update to black 23 (#4482) 2023-02-01 14:23:37 -05:00
test_class.cpp Fix `detail::obj_class_name()` to work correctly for meta classes. (#4436) 2023-01-02 03:46:17 -08:00
test_class.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_const_name.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_const_name.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_constants_and_functions.cpp bugfix: allow noexcept lambdas in C++17. Fix #4565 (#4593) 2023-03-27 20:21:06 -04:00
test_constants_and_functions.py bugfix: allow noexcept lambdas in C++17. Fix #4565 (#4593) 2023-03-27 20:21:06 -04:00
test_copy_move.cpp Introduce recursive_container_traits (#4623) 2023-05-04 22:39:05 -07:00
test_copy_move.py Fix py::cast from pytype rvalue to pytype (#3949) 2022-05-16 13:51:01 -07:00
test_custom_type_casters.cpp Open pybind11 namespace with consistent visility. (#4098) 2022-08-01 11:31:31 -07:00
test_custom_type_casters.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_custom_type_setup.cpp Add `custom_type_setup` attribute (#3287) 2021-09-24 12:08:22 -07:00
test_custom_type_setup.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_docstring_options.cpp Add option for enable/disable enum members in docstring. (#2768) 2022-12-08 23:10:10 -08:00
test_docstring_options.py Add option for enable/disable enum members in docstring. (#2768) 2022-12-08 23:10:10 -08:00
test_eigen_matrix.cpp Introduce a new style of warning suppression based on push/pop (#4285) 2022-11-28 07:39:38 -08:00
test_eigen_matrix.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_eigen_tensor.cpp Fix ODR violations in our Eigen Tensor tests (#4412) 2022-12-20 05:34:00 -08:00
test_eigen_tensor.inl Fix ODR violations in our Eigen Tensor tests (#4412) 2022-12-20 05:34:00 -08:00
test_eigen_tensor.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_enum.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_enum.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_eval.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_eval.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_eval_call.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_exceptions.cpp Always display python type information in cast errors (#4463) 2023-02-09 21:21:17 -08:00
test_exceptions.h Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_exceptions.py Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_factory_constructors.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_factory_constructors.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_gil_scoped.cpp Add `PYBIND11_SIMPLE_GIL_MANAGEMENT` option (cmake, C++ define) (#4216) 2022-10-30 08:57:23 -07:00
test_gil_scoped.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_iostream.cpp Dropping MSVC 2015 (#3722) 2022-02-14 11:36:22 -08:00
test_iostream.py chore(deps): update pre-commit hooks (#4605) 2023-04-28 14:32:32 -04:00
test_kwargs_and_defaults.cpp Introduce a new style of warning suppression based on push/pop (#4285) 2022-11-28 07:39:38 -08:00
test_kwargs_and_defaults.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_local_bindings.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_local_bindings.py chore: update to black 23 (#4482) 2023-02-01 14:23:37 -05:00
test_methods_and_attributes.cpp Elide to-python conversion of setter return values (#4621) 2023-05-08 10:13:54 -07:00
test_methods_and_attributes.py Elide to-python conversion of setter return values (#4621) 2023-05-08 10:13:54 -07:00
test_modules.cpp Add missing error handling to `module_::def_submodule` (#3973) 2022-05-28 16:40:57 -07:00
test_modules.py Remove test code that does not exercise anything in pybind11, but breaks between Python 3.12alpha3 (still working) and 3.12alpha6 (broken): (#4559) 2023-03-09 13:02:34 -08:00
test_multiple_inheritance.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_multiple_inheritance.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_numpy_array.cpp First draft of Eigen::Tensor support (#4201) 2022-10-18 16:54:16 -07:00
test_numpy_array.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_numpy_dtypes.cpp fix: avoid `catch (...)` for expected `import numpy` failures (#3974) 2022-05-26 11:07:40 -04:00
test_numpy_dtypes.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_numpy_vectorize.cpp fix: avoid `catch (...)` for expected `import numpy` failures (#3974) 2022-05-26 11:07:40 -04:00
test_numpy_vectorize.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_opaque_types.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_opaque_types.py chore: drop Python 3.5 (#3719) 2022-02-11 19:06:16 -05:00
test_operator_overloading.cpp Introduce a new style of warning suppression based on push/pop (#4285) 2022-11-28 07:39:38 -08:00
test_operator_overloading.py chore: update to black 23 (#4482) 2023-02-01 14:23:37 -05:00
test_pickling.cpp Test pickling a simple callable (does not work). (#3906) 2022-05-02 12:39:36 -07:00
test_pickling.py Test pickling a simple callable (does not work). (#3906) 2022-05-02 12:39:36 -07:00
test_pytypes.cpp Fix `detail::obj_class_name()` to work correctly for meta classes. (#4436) 2023-01-02 03:46:17 -08:00
test_pytypes.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_sequences_and_iterators.cpp fix: Revert pfect args make iterator (#4234) 2022-10-21 18:04:01 -04:00
test_sequences_and_iterators.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
test_smart_ptr.cpp Open pybind11 namespace with consistent visility. (#4098) 2022-08-01 11:31:31 -07:00
test_smart_ptr.py chore: drop Python 3.5 (#3719) 2022-02-11 19:06:16 -05:00
test_stl.cpp Open pybind11 namespace with consistent visility. (#4098) 2022-08-01 11:31:31 -07:00
test_stl.py chore(deps): update pre-commit hooks (#4605) 2023-04-28 14:32:32 -04:00
test_stl_binders.cpp Introduce recursive_container_traits (#4623) 2023-05-04 22:39:05 -07:00
test_stl_binders.py Introduce recursive_container_traits (#4623) 2023-05-04 22:39:05 -07:00
test_tagbased_polymorphic.cpp Open pybind11 namespace with consistent visility. (#4098) 2022-08-01 11:31:31 -07:00
test_tagbased_polymorphic.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_thread.cpp Fully-automatic clang-format with include reordering (#3713) 2022-02-10 12:17:07 -08:00
test_thread.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_type_caster_pyobject_ptr.cpp Add `type_caster<PyObject>` (#4601) 2023-05-07 10:15:53 -07:00
test_type_caster_pyobject_ptr.py Add `type_caster<PyObject>` (#4601) 2023-05-07 10:15:53 -07:00
test_union.cpp Fix assertion failure for unions (#1685) (#1709) 2019-06-11 23:28:58 +02:00
test_union.py Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688) 2022-02-10 18:28:08 -08:00
test_unnamed_namespace_a.cpp Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_unnamed_namespace_a.py Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_unnamed_namespace_b.cpp Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_unnamed_namespace_b.py Use `std::hash<std::type_index>`, `std::equal_to<std::type_index>` everywhere **except when libc++ is in use** (#4319) 2023-04-25 14:03:24 -07:00
test_vector_unique_ptr_member.cpp Remove stray comment. (Oversight in PR #4631. Noticed by chance.) (#4641) 2023-04-27 07:24:48 -07:00
test_vector_unique_ptr_member.py Introduce `pybind11::detail::is_move_constructible` (#4631) 2023-04-24 00:19:21 -07:00
test_virtual_functions.cpp chore(deps): update pre-commit hooks (#4386) 2022-12-06 10:10:48 -08:00
test_virtual_functions.py chore: move to Ruff and add rules (#4483) 2023-02-22 06:18:55 -08:00
valgrind-numpy-scipy.supp docs: fix various typos (#3075) 2021-07-04 19:58:35 -04:00
valgrind-python.supp chore: get PyPy 3.7 wheels using NumPy 1.20 (#2837) 2021-01-31 17:29:09 -05:00