Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 'upstream/master' (v2.10.0, aa304c9c) #61

Conversation

EricCousineau-TRI
Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI commented Oct 12, 2023

This change is Reviewable

bmerry and others added 30 commits October 1, 2021 09:24
* Add `.keys` and `.values` to bind_map

Both of these implement views (rather than just iterators), and `.items`
is also upgraded to a view. In practical terms, this allows a view to be
iterated multiple times and have its size taken, neither of which works
with an iterator.

The views implement `__len__`, `__iter__`, and the keys view implements
`__contains__`. Testing membership also works in item and value views
because Python falls back to iteration. This won't be optimal
for item values since it's linear rather than O(log n) or O(1), but I
didn't fancy trying to get all the corner cases to match Python
behaviour (tuple of wrong types, wrong length tuple, not a tuple etc).

Missing relative to Python dictionary views is `__reversed__` (only
added to Python in 3.8). Implementing that could break code that binds
custom map classes which don't provide `rbegin`/`rend` (at least without
doing clever things with SFINAE), so I've not tried.

The size increase on my system is 131072 bytes, which is rather large
(5%) but also suspiciously round (2^17) and makes me suspect some
quantisation effect.

* bind_map: support any object in __contains__

Add extra overload of `__contains__` (for both the map itself and
KeysView) which takes an arbitrary object and returns false.

* Take py::object by const reference in __contains__

To keep clang-tidy happy.

* Removing stray `py::` (detected via interactive testing in Google environment).

Co-authored-by: Ralf W. Grosse-Kunstleve <[email protected]>
* Disambiguate free() to use std::free()

* Add cstdlib include
updates:
- [github.com/asottile/pyupgrade: v2.28.0 → v2.29.0](asottile/pyupgrade@v2.28.0...v2.29.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Bumps [ilammy/msvc-dev-cmd](https://github.com/ilammy/msvc-dev-cmd) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/ilammy/msvc-dev-cmd/releases)
- [Commits](ilammy/msvc-dev-cmd@v1.9.0...v1.10.0)

---
updated-dependencies:
- dependency-name: ilammy/msvc-dev-cmd
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add additional pygrep pre-commit hooks

* Remove useless noqas with hook

* Fix all single rst backticks

* Simplify mypy pre-commit hook with upstream fixes

* Add back missing comment

* Add one last pygrep hook
typo correction

pybind11/exec.h → pybind11/eval.h
…nd#3348)

* Add a test showing a flaw in make_key_iterator/make_value_iterator

If the iterator dereference operator returns a value rather than a
reference (and that pair also does not *contain* references),
make_key_iterator and make_value_iterator will return a reference to a
temporary, causing a segfault.

* Fix make_key_iterator/make_value_iterator for prvalue iterators

If an iterator returns a pair<T1, T2> rather than a reference to a pair
or a pair of references, make_key_iterator and make_value_iterator would
return a reference to a temporary, typically leading to a segfault. This
is because the value category of member access to a prvalue is an
xvalue, not a prvalue, so decltype produces an rvalue reference type.
Fix the type calculation to handle this case.

I also removed some decltype parentheses that weren't needed, either
because the expression isn't one of the special cases for decltype or
because decltype was only used for SFINAE. Hopefully that makes the code
a bit more readable.

Closes pybind#3347

* Attempt a workaround for nvcc
updates:
- [github.com/PyCQA/flake8: 3.9.2 → 4.0.1](PyCQA/flake8@3.9.2...4.0.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…ression around Eigen includes. (pybind#3352)

* Adding MSVC C4127 suppression around Eigen includes.

* For MSVC 2015 only: also adding the C4127 suppression to test_eigen.cpp

* Copying original change from PR pybind#3343, with extra line breaks to not run past 99 columns (our desired but currently not enforced limit).
* fix: deprecate make_simple_namespace, fix Python 3.11

* docs: update links
* Add C++ bindings to throw AttributeError

* Fix formatting bug
* fix: MSVC 2017 C++17 on Python 3 regression

* ci: add 3.7 job on CI
updates:
- [github.com/asottile/yesqa: v1.2.3 → v1.3.0](asottile/yesqa@v1.2.3...v1.3.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…ybind#3376)

* fix: the types for return_value_policy_override in optional_caster

`return_value_policy_override` was not being applied correctly in
`optional_caster` in two ways:
- The `is_lvalue_reference` condition referenced `T`, which was the
`optional<T>` type parameter from the class, when it should have used `T_`,
which was the parameter to the `cast` function. `T_` can potentially be a
reference type, but `T` will never be.
- The type parameter passed to `return_value_policy_override` should be
`T::value_type`, not `T`. This matches the way that the other STL container
type casters work.

The result of these issues was that a method/property definition which used a
`reference` or `reference_internal` return value policy would create a Python
value that's bound by reference to a temporary C++ object, resulting in
undefined behavior. For reasons that I was not able to figure out fully, it
seems like this causes problems when using old versions of `boost::optional`,
but not with recent versions of `boost::optional` or the `libstdc++`
implementation of `std::optional`. The issue (that the override to
`return_value_policy::move` is never being applied) is present for all
implementations, it just seems like that somehow doesn't result in problems for
the some implementation of `optional`. This change includes a regression type
with a custom optional-like type which was able to reproduce the issue.

Part of the issue with using the wrong types may have stemmed from the type
variables `T` and `T_` having very similar names. This also changes the type
variables in `optional_caster` to use slightly more descriptive names, which
also more closely follow the naming convention used by the other STL casters.

Fixes pybind#3330

* Fix clang-tidy complaints

* Add missing NOLINT

* Apply a couple more fixes

* fix: support GCC 4.8

* tests: avoid warning about unknown compiler for compilers missing C++17

* Remove unneeded test module attribute

* Change test enum to have more unique int values

Co-authored-by: Aaron Gokaslan <[email protected]>
Co-authored-by: Henry Schreiner <[email protected]>
* ci: support Python 3.11-dev

Also update 3.10 to final, better PyPy usage

* fix: use PyFrame_GetCode on Python 3.9+

* ci: some bitiness of pypy not supported on win

* chore: update CMake support to 3.22rc1 to quiet warning

* fix: use dev version of py to fix Py 3.11

* tests: print proper Eigen version

* ci: include pypy2, not sure why

* ci: avoid running on Python 3.11 for now

* ci: fix runs

* ci: simpler PyPy usage, drop unmaintained scipy + pypy index

* ci: only binary numpy, wait on pypy 3.8

* refactor: address review
pre-commit-ci bot and others added 27 commits July 4, 2022 22:21
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 22.3.0 → 22.6.0](psf/black@22.3.0...22.6.0)
- [github.com/Lucas-C/pre-commit-hooks: v1.2.0 → v1.3.0](Lucas-C/pre-commit-hooks@v1.2.0...v1.3.0)
- [github.com/PyCQA/pylint: v2.14.3 → v2.14.4](pylint-dev/pylint@v2.14.3...v2.14.4)
- [github.com/pre-commit/mirrors-clang-format: v14.0.5 → v14.0.6](pre-commit/mirrors-clang-format@v14.0.5...v14.0.6)

* Update blacken-docs

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Aaron Gokaslan <[email protected]>
* Placeholder commit for 3.11 testing

* Does this fix it?

* Try suggestion

* Placeholder commit for 3.11 testing

* Does this fix it?

* Try suggestion

* fix: try using modern init for embedded interp

Signed-off-by: Henry Schreiner <[email protected]>

* fix: error message changed in 3.11

* fix: apply logic in Python manually

Signed-off-by: Henry Schreiner <[email protected]>

* fix autodetect dynamic attrs in 3.11

* fix: include error message if possible in error

Signed-off-by: Henry Schreiner <[email protected]>

* ci: enable standard Python 3.11 testing

Signed-off-by: Henry Schreiner <[email protected]>

* Make dynamic attrs condtiion exclusive to ver.

Co-authored-by: Henry Schreiner <[email protected]>
* Report `C++ Info:` from `pytest_configure()`

* Use pytest_report_header() as suggested by @Skylion007
… namespace detail). (pybind#4049)

Very minor refactoring to ease development and debugging.

Having to declare a local `std::string` has bugged me many times. Nice to get this little nuisance out of the way.

Extracted from PR pybind#4022, where it is used like this:

```
    std::fprintf(stdout,
                 "\nTYPE_CASTER_ODR_GUARD_IMPL %s %s\n",
                 clean_type_id(intrinsic_type_info.name()).c_str(),
                 source_file_line_from_sloc.c_str());
```
* Properly visit self in >=3.9 traverse

* Add comment about 3.9 behavior
updates:
- [github.com/asottile/pyupgrade: v2.34.0 → v2.37.1](asottile/pyupgrade@v2.34.0...v2.37.1)
- [github.com/hadialqattan/pycln: v1.3.5 → v2.0.1](hadialqattan/pycln@v1.3.5...v2.0.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* docs: try using Furo

* docs: darker output

* docs: improve logo for dark background

Signed-off-by: Henry Schreiner <[email protected]>
* optimize casting of sparse Eigen arrays

* move array

* Revert for safety
* Disable implicit conversion from `0` to `pybind11::handle`.

* Reverse or-ed condition in an attempt to resolve GCC 8.3.0 errors (i386/debian:buster).

* Trying the simpler `std::is_same<T, PyObject *>`

* Add implicit_conversion_from_pytorch_THPObjectPtr_to_handle test.

* Accommodate types with implicit conversions to `PyObject *`, other than `handle` & `handle` subclasses, or integral types.

* Fix copy-paste mishap (picked wrong name).

* Revamp SFINAE construct to actually fix the pytorch issue (already validated against pytorch proper).

The first version of the reduced pytorch code was critically missing the move ctor. The first version of the accompanying test was meaningless.

Note: It turns out the `!std::is_arithmetic<T>` condition is not needed: `int` is not in general implicitly convertible to `PyObject *`, only the literal `0` is.

* Use `NOLINT(performance-noexcept-move-constructor)` for reduced code from the wild (rather than changing the code).

* Use any_of, all_of, negation. It turns out to clang-format nicer.

* Clean up comments for changed code.

* Reduce pytorch situation further, add test for operator ... const.

* Use `none_of` as suggested by @Skylion007

* Add `pure_compile_tests_for_handle_from_PyObject_pointers()`

* Fix inconsequential oversight (retested).

* Factor our `is_pyobj_ptr_or_nullptr_t` to make the SFINAE conditions more readable.

* Remove stray line (oversight).

* Make the `pure_compile_tests_for_handle_from_PyObject_pointers()` "rhs-const-complete", too.

* Remove the temporary PYBIND11_UNDO_PR4008 `#ifdef`.
Before auto-format

# Conflicts:
#	.github/workflows/ci.yml
#	include/pybind11/detail/type_caster_base.h
#	include/pybind11/eigen.h
#	include/pybind11/pybind11.h
# Conflicts:
#	include/pybind11/cast.h
#	include/pybind11/detail/common.h
#	include/pybind11/detail/internals.h
#	include/pybind11/detail/type_caster_base.h
#	include/pybind11/eigen.h
#	include/pybind11/numpy.h
#	include/pybind11/pybind11.h
#	include/pybind11/pytypes.h
#	tests/test_builtin_casters.cpp
#	tests/test_eigen.cpp
#	tests/test_multiple_inheritance.cpp
# Conflicts:
#	.clang-format
#	.clang-tidy
#	.github/CONTRIBUTING.md
#	.github/workflows/ci.yml
#	.github/workflows/configure.yml
#	.github/workflows/upstream.yml
#	.pre-commit-config.yaml
#	docs/Doxyfile
#	docs/advanced/cast/overview.rst
#	docs/advanced/exceptions.rst
#	docs/advanced/functions.rst
#	docs/advanced/pycpp/numpy.rst
#	docs/benchmark.py
#	docs/changelog.rst
#	docs/classes.rst
#	docs/compiling.rst
#	docs/requirements.txt
#	docs/upgrade.rst
#	include/pybind11/attr.h
#	include/pybind11/buffer_info.h
#	include/pybind11/cast.h
#	include/pybind11/chrono.h
#	include/pybind11/detail/class.h
#	include/pybind11/detail/common.h
#	include/pybind11/detail/descr.h
#	include/pybind11/detail/init.h
#	include/pybind11/detail/internals.h
#	include/pybind11/detail/type_caster_base.h
#	include/pybind11/eigen.h
#	include/pybind11/embed.h
#	include/pybind11/eval.h
#	include/pybind11/functional.h
#	include/pybind11/gil.h
#	include/pybind11/iostream.h
#	include/pybind11/numpy.h
#	include/pybind11/operators.h
#	include/pybind11/pybind11.h
#	include/pybind11/pytypes.h
#	include/pybind11/stl.h
#	include/pybind11/stl/filesystem.h
#	include/pybind11/stl_bind.h
#	noxfile.py
#	pybind11/__init__.py
#	pybind11/_version.py
#	pybind11/_version.pyi
#	pybind11/setup_helpers.py
#	pybind11/setup_helpers.pyi
#	pyproject.toml
#	setup.cfg
#	setup.py
#	tests/CMakeLists.txt
#	tests/env.py
#	tests/extra_python_package/test_files.py
#	tests/extra_setuptools/test_setuphelper.py
#	tests/local_bindings.h
#	tests/object.h
#	tests/pybind11_cross_module_tests.cpp
#	tests/pybind11_tests.h
#	tests/requirements.txt
#	tests/test_buffers.cpp
#	tests/test_buffers.py
#	tests/test_builtin_casters.cpp
#	tests/test_builtin_casters.py
#	tests/test_call_policies.cpp
#	tests/test_callbacks.cpp
#	tests/test_callbacks.py
#	tests/test_chrono.py
#	tests/test_class.cpp
#	tests/test_cmake_build/test.py
#	tests/test_constants_and_functions.cpp
#	tests/test_copy_move.cpp
#	tests/test_custom_type_casters.cpp
#	tests/test_custom_type_setup.py
#	tests/test_eigen.cpp
#	tests/test_eigen.py
#	tests/test_embed/test_interpreter.cpp
#	tests/test_embed/test_interpreter.py
#	tests/test_embed/test_trampoline.py
#	tests/test_enum.cpp
#	tests/test_enum.py
#	tests/test_eval.cpp
#	tests/test_exceptions.cpp
#	tests/test_exceptions.h
#	tests/test_exceptions.py
#	tests/test_factory_constructors.cpp
#	tests/test_factory_constructors.py
#	tests/test_gil_scoped.cpp
#	tests/test_iostream.py
#	tests/test_kwargs_and_defaults.cpp
#	tests/test_kwargs_and_defaults.py
#	tests/test_local_bindings.cpp
#	tests/test_methods_and_attributes.cpp
#	tests/test_methods_and_attributes.py
#	tests/test_modules.cpp
#	tests/test_modules.py
#	tests/test_multiple_inheritance.cpp
#	tests/test_multiple_inheritance.py
#	tests/test_numpy_array.cpp
#	tests/test_numpy_dtypes.cpp
#	tests/test_numpy_dtypes.py
#	tests/test_numpy_vectorize.cpp
#	tests/test_opaque_types.cpp
#	tests/test_operator_overloading.cpp
#	tests/test_ownership_transfer.cpp
#	tests/test_pickling.cpp
#	tests/test_pytypes.cpp
#	tests/test_pytypes.py
#	tests/test_sequences_and_iterators.cpp
#	tests/test_sequences_and_iterators.py
#	tests/test_smart_ptr.cpp
#	tests/test_stl.cpp
#	tests/test_stl_binders.py
#	tests/test_tagbased_polymorphic.cpp
#	tests/test_thread.cpp
#	tests/test_thread.py
#	tests/test_virtual_functions.cpp
#	tests/test_virtual_functions.py
#	tools/libsize.py
#	tools/pybind11NewTools.cmake
#	tools/pybind11Tools.cmake
@EricCousineau-TRI
Copy link
Collaborator Author

superseded by #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.