pybind11/tests
Bruce Merry ee0c5ee405
Add make_value_iterator (#3271)
* Add make_value_iterator

This is the counterpart to make_key_iterator, and will allow
implementing a `value` method in `bind_map` (although doing so is left
for a subsequent PR).

I made a few design changes to reduce copy-and-paste boilerplate.
Previously detail::iterator_state had a boolean template parameter to
indicate whether it was being used for make_iterator or
make_key_iterator. I replaced the boolean with a class that determines
how to dereference the iterator. This allows for a generic
implementation of `__next__`.

I also added the ValueType and Extra... parameters to the iterator_state
template args, because I think it was a bug that they were missing: if
make_iterator is called twice with different values of these, only the
first set has effect (because the state class is only registered once).
There is still a potential issue in that the *values* of the extra
arguments are latched on the first call, but since most policies are
empty classes this should be even less common.

* Add some remove_cv_t to appease clang-tidy

* Make iterator_access and friends take reference

For some reason I'd accidentally made it take a const value, which
caused some issues with third-party packages.

* Another attempt to remove remove_cv_t from iterators

Some of the return types were const (non-reference) types because of the
pecularities of decltype: `decltype((*it).first)` is the *declared* type
of the member of the pair, rather than the type of the expression. So if
the reference type of the iterator is `pair<const int, int> &`, then the
decltype is `const int`. Wrapping an extra set of parentheses to form
`decltype(((*it).first))` would instead give `const int &`.

This means that the existing make_key_iterator actually returns by value
from `__next__`, rather than by reference. Since for mapping types, keys
are always const, this probably hasn't been noticed, but it will affect
make_value_iterator if the Python code tries to mutate the returned
objects. I've changed things to use double parentheses so that
make_iterator, make_key_iterator and make_value_iterator should now all
return the reference type of the iterator. I'll still need to add a test
for that; for now I'm just checking whether I can keep Clang-Tidy happy.

* Add back some NOLINTNEXTLINE to appease Clang-Tidy

This is favoured over using remove_cv_t because in some cases a const
value return type is deliberate (particularly for Eigen).

* Add a unit test for iterator referencing

Ensure that make_iterator, make_key_iterator and make_value_iterator
return references to the container elements, rather than copies. The
test for make_key_iterator fails to compile on master, which gives me
confidence that this branch has fixed it.

* Make the iterator_access etc operator() const

I'm actually a little surprised it compiled at all given that the
operator() is called on a temporary, but I don't claim to fully
understand all the different value types in C++11.

* Attempt to work around compiler bugs

https://godbolt.org/ shows an example where ICC gets the wrong result
for a decltype used as the default for a template argument, and CI also
showed problems with PGI. This is a shot in the dark to see if it fixes
things.

* Make a test constructor explicit (Clang-Tidy)

* Fix unit test on GCC 4.8.5

It seems to require the arguments to the std::pair constructor to be
implicitly convertible to the types in the pair, rather than just
requiring is_constructible.

* Remove DOXYGEN_SHOULD_SKIP_THIS guards

Now that a complex decltype expression has been replaced by a simpler
nested type, I'm hoping Doxygen will be able to build it without issues.

* Add comment to explain iterator_state template params
2021-09-21 13:37:19 -04:00
..
extra_python_package fix: the CMake config in Python package had a hard coded path (#3144) 2021-07-27 17:23:52 -04:00
extra_setuptools maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_cmake_build fix: Set __file__ constant when using eval_file (#1300) (#3233) 2021-09-09 14:06:33 -04:00
test_embed CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
CMakeLists.txt Fix thread safety for pybind11 loader_life_support (#3237) 2021-09-10 12:29:21 -04:00
conftest.py style: use Black everywhere (#2594) 2020-10-16 16:38:13 -04:00
constructor_stats.h refactor: module -> module_ with typedef (#2544) 2020-10-03 13:38:03 -04:00
cross_module_gil_utils.cpp Make sure detail::get_internals acquires the GIL before making Python calls. (#1836) 2019-07-15 16:47:02 +02:00
env.py env: Add surrogate for pytest.deprecated_call for ptyest<3.9 (#2923) 2021-04-02 14:34:09 -04:00
local_bindings.h CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
object.h CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
pybind11_cross_module_tests.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
pybind11_tests.cpp refactor: module -> module_ with typedef (#2544) 2020-10-03 13:38:03 -04:00
pybind11_tests.h CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
pytest.ini Make sure all warnings in pytest get turned into errors (#2838) 2021-02-01 14:52:20 +01:00
requirements.txt tests: fix pytest usage on Python 3.10 (#3221) 2021-08-26 10:52:13 -07:00
test_async.cpp refactor: module -> module_ with typedef (#2544) 2020-10-03 13:38:03 -04:00
test_async.py tests: cleanup and ci hardening (#2397) 2020-08-16 16:02:12 -04:00
test_buffers.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_buffers.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_builtin_casters.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_builtin_casters.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_call_policies.cpp functions: Add doc on incorrect argument index (#2979) 2021-05-06 10:13:30 -04:00
test_call_policies.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_callbacks.cpp fix: memory leak in cpp_function (#3228) (#3229) 2021-08-30 21:48:33 -04:00
test_callbacks.py fix: memory leak in cpp_function (#3228) (#3229) 2021-08-30 21:48:33 -04:00
test_chrono.cpp fix: allow assignment of time points of resolutions other than that of a system clock (#2481) 2020-09-13 10:24:00 -04:00
test_chrono.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_class.cpp Fix test case with __new__ (#3285) 2021-09-20 16:03:21 -04:00
test_class.py Enable defining custom __new__ (#3265) 2021-09-20 10:42:14 -04:00
test_constants_and_functions.cpp Removing __INTEL_COMPILER section from pragma block at the top of pybind11.h (#3135) 2021-07-27 15:33:31 -07:00
test_constants_and_functions.py Plug leaking function_records in cpp_function initialization in case of exceptions (found by Valgrind in #2746) (#2756) 2021-01-14 19:34:32 +01:00
test_copy_move.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_copy_move.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_custom_type_casters.cpp fix(clang-tidy): performance fixes applied in tests and CI (#3051) 2021-06-22 12:11:54 -04:00
test_custom_type_casters.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_docstring_options.cpp fix: do not set docstring for function when empty (#2745) 2020-12-27 22:56:30 -05:00
test_docstring_options.py fix: do not set docstring for function when empty (#2745) 2020-12-27 22:56:30 -05:00
test_eigen.cpp maint(Clang-Tidy): readability-const-return (#3254) 2021-09-09 21:27:36 -07:00
test_eigen.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_enum.cpp Fix enum value's __int__ returning non-int when underlying type is bool or of char type (#1334) 2021-08-26 14:34:24 -07:00
test_enum.py Minor follow-on to PR #1334 (Fix enum value's __int__ returning non-int when underlying type is bool or of char type) (#3232) 2021-08-31 08:52:04 -07:00
test_eval_call.py style: use Black everywhere (#2594) 2020-10-16 16:38:13 -04:00
test_eval.cpp test_eval: Show example of working closure (#2743) 2021-08-06 15:51:53 -04:00
test_eval.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_exceptions.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_exceptions.h fix: Mingw64 corrected and add a CI job to test it (#3132) 2021-07-30 13:48:41 -04:00
test_exceptions.py Clone of @virtuald's PR #2112 with minor enhancements. (#3215) 2021-08-23 17:30:01 -07:00
test_factory_constructors.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_factory_constructors.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_gil_scoped.cpp fix(clang-tidy): performance fixes applied in tests and CI (#3051) 2021-06-22 12:11:54 -04:00
test_gil_scoped.py style: use Black everywhere (#2594) 2020-10-16 16:38:13 -04:00
test_iostream.cpp Adding iostream.h thread-safety documentation. (#2995) 2021-07-12 13:39:06 -07:00
test_iostream.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_kwargs_and_defaults.cpp NOLINT reduction (#3096) 2021-07-12 13:10:28 -07:00
test_kwargs_and_defaults.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_local_bindings.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_local_bindings.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_methods_and_attributes.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_methods_and_attributes.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_modules.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_modules.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_multiple_inheritance.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_multiple_inheritance.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_numpy_array.cpp view for numpy arrays (#987) 2021-08-26 14:11:01 -07:00
test_numpy_array.py view for numpy arrays (#987) 2021-08-26 14:11:01 -07:00
test_numpy_dtypes.cpp maint(clang-tidy): Bugprone enable checks (#3166) 2021-08-06 14:30:28 -04:00
test_numpy_dtypes.py ci: extend msys2 mingw CI (#3207) 2021-08-19 14:42:55 -04:00
test_numpy_vectorize.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_numpy_vectorize.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_opaque_types.cpp fix(clang-tidy): performance fixes applied in tests and CI (#3051) 2021-06-22 12:11:54 -04:00
test_opaque_types.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_operator_overloading.cpp fix(clang-tidy): performance fixes applied in tests and CI (#3051) 2021-06-22 12:11:54 -04:00
test_operator_overloading.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_pickling.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_pickling.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_pytypes.cpp Follow-on to PR #3254, to address user code breakages. (#3263) 2021-09-12 19:53:26 -07:00
test_pytypes.py Eliminate duplicate TLS keys for loader_life_support stack (#3275) 2021-09-20 04:57:38 -07:00
test_sequences_and_iterators.cpp Add make_value_iterator (#3271) 2021-09-21 13:37:19 -04:00
test_sequences_and_iterators.py Add make_value_iterator (#3271) 2021-09-21 13:37:19 -04:00
test_smart_ptr.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_smart_ptr.py Fix various minor memory leaks in the tests (found by Valgrind in #2746) (#2758) 2021-01-01 17:05:22 +01:00
test_stl_binders.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_stl_binders.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_stl.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_stl.py maint(precommit): Apply isort (#3195) 2021-08-13 12:37:05 -04:00
test_tagbased_polymorphic.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_tagbased_polymorphic.py style: use Black everywhere (#2594) 2020-10-16 16:38:13 -04:00
test_thread.cpp Fix thread safety for pybind11 loader_life_support (#3237) 2021-09-10 12:29:21 -04:00
test_thread.py Fix thread safety for pybind11 loader_life_support (#3237) 2021-09-10 12:29:21 -04:00
test_union.cpp Fix assertion failure for unions (#1685) (#1709) 2019-06-11 23:28:58 +02:00
test_union.py ci: GHA basic format & pre-commit (#2309) 2020-07-20 13:35:21 -04:00
test_virtual_functions.cpp CodeHealth: Enabling clang-tidy google-explicit-constructor (#3250) 2021-09-08 18:53:38 -07:00
test_virtual_functions.py Add a Valgrind build on debug Python 3.9 (#2746) 2021-01-15 21:07:31 +01: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