Commit Graph

2334 Commits

Author SHA1 Message Date
Henry Schreiner
3f8db35232
ci: try newer images 2021-11-18 08:38:50 -05:00
Henry Schreiner
72282f75a1
ci: support development releases of Python (#3419)
* ci: support development releases of Python

* fix: better PyPy support

* fix: patch over a few more pypy issues

* Try to patch

* Properly follow pep667

* Fix typo

* Whoops, 667 not in yet

* For testing

* More testing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Try to backport

* Try to simplify fix

* Nail down the fix

* Try pypy workaround

* Typo

* one last typo

* Replacing 0x03110000 with 0x030B0000

* Add TODO. Drop PyPy

* Fix typo

* Revert catch upgrade

* fix: minor cleanup, try pypy again

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2021-11-17 09:44:19 -05:00
Guillaume Jacquenot
1eb59963c7
Removed duplicated word in docs/advanced/exceptions.rst (#3476) 2021-11-16 17:32:01 -05:00
Sergiu Deitsch
d2b2131603
cmake: report version type in the version string (#3472) 2021-11-16 10:03:41 -05:00
pre-commit-ci[bot]
9422d98fcc
[pre-commit.ci] pre-commit autoupdate (#3473)
updates:
- [github.com/PyCQA/isort: 5.10.0 → 5.10.1](https://github.com/PyCQA/isort/compare/5.10.0...5.10.1)
- [github.com/shellcheck-py/shellcheck-py: v0.7.2.1 → v0.8.0.1](https://github.com/shellcheck-py/shellcheck-py/compare/v0.7.2.1...v0.8.0.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-15 22:48:39 -05:00
Trigve
afdc09deda
[master] Wrong caching of overrides (#3465)
* override: Fix wrong caching of the overrides

There was a problem when the python type, which was stored in override
cache for C++ functions, was destroyed and  the record wasn't removed from the
override cache. Therefor, dangling pointer was stored there. Then when the
memory was reused and new type was allocated at the given address and the
method with the same name (as previously stored in the cache) was actually
overridden in python, it would wrongly find it in the override cache for C++
functions and therefor override from python wouldn't be called.
The fix is to erase the type from the override cache when the type is destroyed.

* test: Pass by const ref instead of by value (clang-tidy)

* test: Rename classes and move to different files

Rename the classes and files so they're no too generic. Also, better place to
test the stuff is in test_virtual_functions.cpp/.py as we're basically testing
the virtual functions/trampolines.

* Add TODO for erasure code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-15 13:36:41 -05:00
Henry Schreiner
270b11d502
Revert "style: drop pycln" (#3466)
* Revert "style: drop pycln (#3397)"

This reverts commit 606f81a966.

* Update .pre-commit-config.yaml
2021-11-13 21:32:58 -05:00
Guillaume Jacquenot
e450eb62c2
Removed duplicated word in docs/advanced/cast/eigen.rst (#3458) 2021-11-12 10:53:43 -05:00
Henry Schreiner
aebd21b53c
docs: rework CI a bit, more modern skipping (#3424)
* docs: rework CI a bit, more modern skipping

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-10 12:13:10 -05:00
Antony Lee
b11ff912a6
fix(setup =_helpers): don't add -g0 CFLAGS sets -g (#3436)
On Unix, setuptools prepends $CFLAGS and $CPPFLAGS to the compiler flags
(they always come before extra_compile_args and anything else; see
distutils.sysconfig.customize_compiler).  In practice, the environment
variables are useful e.g. to quickly generate a debug build (e.g. by
setting CFLAGS=-g), but Pybind11Extension currently unconditionally
overwrites this with -g0.

Instead, check the environment variables and only insert -g0 if not
overridden by them.
2021-11-08 16:27:32 -05:00
pre-commit-ci[bot]
b322018e15
[pre-commit.ci] pre-commit autoupdate (#3449)
updates:
- [github.com/PyCQA/isort: 5.9.3 → 5.10.0](https://github.com/PyCQA/isort/compare/5.9.3...5.10.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-08 15:56:20 -05:00
Boris Rasin
01f938e799
fix: add missing std::forward calls (#3443)
* fix: add missing std::forward calls

Two of the four cpp_function overloads are missing std::forward calls, which seems like a simple oversight.

* add test for https://github.com/pybind/pybind11/pull/3443

* add py tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix test

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-07 18:35:25 -05:00
Henry Schreiner
a61e354e42
docs: touch up manual release suggestion (#3422) 2021-11-05 22:48:27 -04:00
pre-commit-ci[bot]
6de30d3172
[pre-commit.ci] pre-commit autoupdate (#3432)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/psf/black: 21.9b0 → 21.10b0](https://github.com/psf/black/compare/21.9b0...21.10b0)

* Update blacken-docs too

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2021-11-01 17:22:12 -04:00
Chad B. Hovey
dd2d12721c
Correct "which" versus "that" error. (#3430) 2021-11-01 12:01:27 -04:00
Jason Rhinelander
e7c9753f1d
feat: allow kw-only args after a py::args (#3402)
* Simply has_kw_only_args handling

This simplifies tracking the number of kw-only args by instead tracking
the number of positional arguments (which is really what we care about
everywhere this is used).

* Allow keyword-only arguments to follow py::args

This removes the constraint that py::args has to be last (or
second-last, with py::kwargs) and instead makes py::args imply
py::kw_only for any remaining arguments, allowing you to bind a function
that works the same way as a Python function such as:

    def f(a, *args, b):
        return a * b + sum(args)

    f(10, 1, 2, 3, b=20)  # == 206

With this change, you can bind such a function using:

    m.def("f", [](int a, py::args args, int b) { /* ... */ },
        "a"_a, "b"_a);

Or, to be more explicit about the keyword-only arguments:

    m.def("g", [](int a, py::args args, int b) { /* ... */ },
        "a"_a, py::kw_only{}, "b"_a);

(The only difference between the two is that the latter will fail at
binding time if the `kw_only{}` doesn't match the `py::args` position).

This doesn't affect backwards compatibility at all because, currently,
you can't have a py::args anywhere except the end/2nd-last.

* Take args/kwargs by const lvalue ref

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-28 23:16:55 -04:00
Ralf W. Grosse-Kunstleve
a80b22374a chore: get back to work after 2.8.1
[skip ci]
2021-10-27 15:15:11 -07:00
Ralf W. Grosse-Kunstleve
f7b499615e
[skip ci] Tweaks in preparation for the 2.8.1 release. (#3421) 2021-10-27 14:35:10 -07:00
Henry Schreiner
f1594cb960
docs: changelog update for 2.8.1 (#3416)
* docs: changelog update for 2.8.1

* chore: add one more entry

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-10-27 15:08:59 -04:00
Henry Schreiner
90707b46f2
fix(build): support conan's multiple includes of all files (#3420) 2021-10-27 15:06:02 -04:00
Henry Schreiner
e7e2c79f3f
fix: improve support for Python 3.11-dev (#3368)
* 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
2021-10-26 14:50:34 -04:00
Ryan Cahoon
c2d3e220bd
fix: the types for return_value_policy_override in optional_caster (#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 #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 <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
2021-10-25 19:04:45 -07:00
pre-commit-ci[bot]
d45a88105c
[pre-commit.ci] pre-commit autoupdate (#3409)
updates:
- [github.com/asottile/yesqa: v1.2.3 → v1.3.0](https://github.com/asottile/yesqa/compare/v1.2.3...v1.3.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-10-25 16:06:13 -04:00
Henry Schreiner
9379b399d9
fix: MSVC 2017 C++17 on Python 3 regression (#3407)
* fix: MSVC 2017 C++17 on Python 3 regression

* ci: add 3.7 job on CI
2021-10-25 16:01:19 -04:00
Aaron Gokaslan
78ee782bd4
feat: Add C++ binding to throw AttributeError (#3387)
* Add C++ bindings to throw AttributeError

* Fix formatting bug
2021-10-23 00:07:22 -04:00
Dmitry Yershov
076c89fc54
tests: test recursive dispatch using visitor pattern (#3365) 2021-10-22 17:09:15 -04:00
Henry Schreiner
606f81a966
style: drop pycln (#3397) 2021-10-22 16:38:40 -04:00
Geoffrey Gunter
2d6014e417
docs: fix minor typo (#3390) 2021-10-21 10:37:54 -04:00
Henry Schreiner
f791dc8648
fix: deprecate make_simple_namespace, fix Python 3.11 (#3374)
* fix: deprecate make_simple_namespace, fix Python 3.11

* docs: update links
2021-10-19 14:39:29 -04:00
Henry Schreiner
931f66440f
ci: cancel in-progress on repeated pushes (#3370) 2021-10-17 21:40:10 -04:00
Jerome Robert
56b49c2be2
ci: fix mingw checks by pinning (#3375)
* Workaround for https://github.com/msys2/setup-msys2/issues/167
* Adapted from 05036cb24d
2021-10-17 21:38:41 -04:00
Ralf W. Grosse-Kunstleve
7c580586f8
Correct options on Eigen::MappedSparseMatrix & adding MSVC C4127 suppression around Eigen includes. (#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 #3343, with extra line breaks to not run past 99 columns (our desired but currently not enforced limit).
2021-10-11 13:13:01 -07:00
pre-commit-ci[bot]
02c05573d9
[pre-commit.ci] pre-commit autoupdate (#3353)
updates:
- [github.com/PyCQA/flake8: 3.9.2 → 4.0.1](https://github.com/PyCQA/flake8/compare/3.9.2...4.0.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-10-11 16:03:19 -04:00
Bruce Merry
8a7c266d26
Fix make_key_iterator/make_value_iterator for prvalue iterators (#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 #3347

* Attempt a workaround for nvcc
2021-10-11 08:35:39 -07:00
NaDDu
750e38dcfd
Update eval.h (#3344)
typo correction

pybind11/exec.h → pybind11/eval.h
2021-10-09 11:38:34 -04:00
Aaron Gokaslan
f4c81e0877
maint: Add additional linter-related pre-commit hooks (#3337)
* 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
2021-10-08 08:38:04 -04:00
dependabot[bot]
ed09664f06
chore(deps): bump ilammy/msvc-dev-cmd from 1.9.0 to 1.10.0 (#3338)
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](https://github.com/ilammy/msvc-dev-cmd/compare/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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-08 08:27:52 -04:00
Bruce Merry
47ed124f37
Fix some formatting in the v2.8.0 changelog (#3339)
[skipci]
2021-10-08 08:27:38 -04:00
Henry Schreiner
ba9f919b85
chore: get back to work after 2.8.0 2021-10-04 17:37:27 -04:00
pre-commit-ci[bot]
97976c16fb
[pre-commit.ci] pre-commit autoupdate (#3325)
updates:
- [github.com/asottile/pyupgrade: v2.28.0 → v2.29.0](https://github.com/asottile/pyupgrade/compare/v2.28.0...v2.29.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-10-04 16:38:31 -04:00
Henry Schreiner
3747dc2c4f
Revert "All -DDOWNLOAD_EIGEN=OFF (to work around gitlab eigen outage)." (#3326)
This reverts commit 9f146a5622.
2021-10-04 16:38:15 -04:00
Henry Schreiner
c9a319c607
chore: version 2.8.0 final 2021-10-04 15:33:58 -04:00
Henry Schreiner
20aae3e61a ci: disable Eigen due to Cert issue on CentOS 2021-10-04 15:20:10 -04:00
Henry Schreiner
591db0b930 docs: update CHANGELOG for 2.8 2021-10-04 15:20:10 -04:00
Ralf W. Grosse-Kunstleve
9f146a5622 All -DDOWNLOAD_EIGEN=OFF (to work around gitlab eigen outage). 2021-10-04 10:06:12 -07:00
Henry Schreiner
d7a7edc12b tests: support Eigen configuration 2021-10-04 10:06:12 -07:00
Aaron Gokaslan
ad96655605
fix: replace free() with std::free() (#3321)
* Disambiguate free() to use std::free()

* Add cstdlib include
2021-10-03 20:15:37 -04:00
Bruce Merry
b3573ac961
feat: add .keys and .values to bind_map (#3310)
* 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 <rwgk@google.com>
2021-10-01 09:24:36 -04:00
xaedes
b4e1ab8caa
Docs: Demonstrate non-enum internal types in example (#3314)
* Docs: Demonstrate non-enum internal types in example

Previously example only demonstrated internal enumeration type. 
To show that it works for other internal types the same way the example was updated with an additional struct Pet::Attributes type.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-09-30 14:45:06 -04:00
Henry Schreiner
a1830d5e6e
docs: mention title conventions in PR template (#3313) 2021-09-29 06:18:58 -04:00