Commit Graph

869 Commits

Author SHA1 Message Date
Ralf W. Grosse-Kunstleve
d5125eaf1e Merge branch 'master' into sh_merge_master 2022-05-05 16:12:58 -07:00
Ed Catmur
68a0b2dfd8
Add anyset & frozenset, enable copying (cast) to std::set (#3901)
* Add frozenset, and allow it cast to std::set

For the reverse direction, std::set still casts to set. This is in concordance with the behavior for sequence containers, where e.g. tuple casts to std::vector but std::vector casts to list.

Extracted from #3886.

* Rename set_base to any_set to match Python C API

since this will be part of pybind11 public API

* PR: static_cast, anyset

* Add tests for frozenset

and rename anyset methods

* Remove frozenset default ctor, add tests

Making frozenset non-default constructible means that we need to adjust pyobject_caster to not require that its value is default constructible, by initializing value to a nil handle.  This also allows writing C++ functions taking anyset, and is arguably a performance improvement, since there is no need to allocate an object that will just be replaced by load.

Add some more tests, including anyset::empty, anyset::size, set::add and set::clear.

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

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

* Add rationale to `pyobject_caster` default ctor

* Remove ineffectual protected: access control

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-05 12:09:56 -07:00
Ralf W. Grosse-Kunstleve
2ee1e6445d Merge branch 'master' into sh_merge_master 2022-05-02 12:41:48 -07:00
Ralf W. Grosse-Kunstleve
287e4f233d
Test pickling a simple callable (does not work). (#3906)
* Test pickling a simple callable (does not work).

Currently only documents that it does not work. Starting point for future fix.

* Use re.search to accommodate variations of the TypeError message.

* PyPy: exercise full dumps/loads cycle.

* Adding explicit "broken" comment.
2022-05-02 12:39:36 -07:00
Michael Voznesensky
f0b9f755e4
Replace error printing code gated by NDEBUG with a new flag: PYBIND11_DETAILED_ERROR_MESSAGES (#3913)
* Update cast.h

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

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

* Move definition to detail/common, change name, apply everywhere

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

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

* Rename debug_enabled in tests to detailed_error_messages_enabled
2022-05-02 15:30:19 -04:00
Ed Catmur
9bc2704430
Add tests for cast from tuple to sequence containers (#3900)
We already test that tuple can cast to std::vector and std::deque; add tests for std::vector<bool>, std::list and
std::valarray.

Extracted from #3886.
2022-04-24 14:39:47 -07:00
Aaron Gokaslan
1c636f4dce
chore: Change numpy dtype from_args call sig to const ref (#3878)
* Change numpy from_args call signature to avoid copy

* Reorder ctors

* Rename arg

* Fix unnecessary move

* Fix clang-tidy and Add a few missing moves to memory_view pytype
2022-04-18 11:11:24 -04:00
Aaron Gokaslan
fbcde3f0af
chore: enable clang-tidy check modernize-use-nullptr (#3881)
* Enable clang-tidy check modernize-use-nullptr

* Sort clang-tidy

* Sorted again
2022-04-18 11:09:45 -04:00
Ralf W. Grosse-Kunstleve
3d1cb7be83 Merge branch 'master' into sh_merge_master 2022-04-17 22:16:08 -07:00
Xiaofei Wang
7064d43bc9
[smart_holder] Add a new return value policy return_as_bytes (#3838)
* Add return_as_bytes policy

* Fix format

* Fix test failures

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

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

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

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

* Fix std::variant

* Resolve comments

* Note this policy experimental

* Add tests for `return_as_bytes` with `def_property`.

* Change comment for the new return_as_bytes enum to note that the policy is not available on master.

* Applying pr3838_sh.patch (exactly as used Google-internally since 2022-03-31).

* Add `case return_as_bytes` to `switch`es in detail/type_caster_base.h and eigen.h

Based on systematic review under https://github.com/pybind/pybind11/pull/3838#issuecomment-1094390333

* Add missing break (clang-tidy).

* More clang-tidy fixes (this time around clang-tidy was run interactively to pre-empt repeat trips through the CI).

* Underscore prefix: _return_as_bytes

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>
2022-04-15 10:17:34 -07:00
Oleksandr Pavlyk
ba7a0fac73
Expand dtype accessors (#3868)
* Added constructor based on typenum, based on PyArray_DescrFromType

Added accessors for typenum, alignment, byteorder and flags fields of
PyArray_Descr struct.

* Added tests for new py::dtype constructor, and for accessors

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

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

* Fixed the comment for alignment method

* Update include/pybind11/numpy.h

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>

* [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>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-04-14 10:53:16 -04:00
Oleksandr Pavlyk
fa98804a07
Adds set_name method of pybind11::capsule class (#3866)
* Adds set_name method of pybind11::capsule class

This calls PyCapsule_SetName on the underlying capsule object.

modified destructors to query capsules's Name

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

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

Handle possible exception thrown by PyCapsule_GetName

Also removed accidentally reintroduced use of `const char *&`.

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

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

Fixed function name

* Introduced private static function to reuse get_name_or_throw

* added tests for capsule renaming

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

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

* handle python error in flight

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

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

* Initialized PyObject * variables to nullptr

* use write-unraisable if PyCapsule_GetName raises

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

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

* get_name_or_throw->get_name_no_throw

If PyCapsule_GetName raises an error we should write as unraisable
to consume it and notify user, and then restore the error in flight if any.
This way this method called from destructor would not modify interpreter
error state.

* used error_scope struct

* Renamed get_name_no_throw->get_name_in_error_scope

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-14 10:51:27 -04:00
Ralf W. Grosse-Kunstleve
08ea85b0ac Merge branch 'master' into sh_merge_master 2022-03-21 22:59:39 -07:00
Laramie Leavitt
b22ee64c73
Add type_caster<std::monostate> (#3818)
* Add type_caster<std::monostate> for std::variant

Add type_caster<std::monostate>, allowing std::variant<std::monostate, ...>

* Add  variant<std::monostate, ...> test methods

* Add std::monostate tests

* Update test_stl.py

Remove erroneous extra tests

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

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

* Update test fn name

* And update the doc() test

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-21 22:58:04 -07:00
Oleksandr Pavlyk
6bbc5a464b PYBIND11_OBJECT_CVT should use namespace for error_already_set() (#3797)
* PYBIND11_OBJECT_CVT should use namespace for error_already_set()

This change makes the macro usable outside of pybind11 namespace.

* added test for use of PYBIND11_OBJECT_CVT for classes in external to pybind11 namespaces

* Extended test_pytypes.cpp and test_pytest.py

The added test defines a dummy function that takes a custom-defined class external::float_
that uses PYBIND11_OBJECT_CVT

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

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

* fixed issues pointed out by CI

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

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

* fixed memory leak in default constructor

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-18 11:15:52 -07:00
Xiaofei Wang
7405976aa4
Fixes issue #3801 (#3807)
* Fixes issue

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

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

* Fix lint error

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

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

* Fix flake8

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

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

* Fix test

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

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

* Fix clang tidy

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

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

* Fix again

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

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

* Fix test

* Add comments

* Try fix Valgrind

* Resolve comments

* [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>
2022-03-18 11:08:20 -07:00
Oleksandr Pavlyk
91a6e129d9
PYBIND11_OBJECT_CVT should use namespace for error_already_set() (#3797)
* PYBIND11_OBJECT_CVT should use namespace for error_already_set()

This change makes the macro usable outside of pybind11 namespace.

* added test for use of PYBIND11_OBJECT_CVT for classes in external to pybind11 namespaces

* Extended test_pytypes.cpp and test_pytest.py

The added test defines a dummy function that takes a custom-defined class external::float_
that uses PYBIND11_OBJECT_CVT

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

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

* fixed issues pointed out by CI

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

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

* fixed memory leak in default constructor

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-11 12:18:25 -08:00
Xiaofei Wang
9d4b4dffce
Fixes issue #3788 (#3796)
* Reproducer for https://github.com/pybind/pybind11/issues/3788

Expected to build & run as-is. Uncommenting reproduces the infinite recursion.

* Moving try_as_void_ptr_capsule() to the end of load_impl()

* Moving new test into the existing test_class_sh_void_ptr_capsule

* Experiment

* Remove comments and simplify the test cases.

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

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

Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-10 16:18:24 -08:00
Ralf W. Grosse-Kunstleve
4c4b33f142 Merge branch 'master' into sh_merge_master 2022-02-25 13:26:43 -08:00
Eric Cousineau
f495dfc433
cast: Qualify symbol usage in PYBIND11_TYPE_CASTER (#3758)
* cast: Qualify symbol usage in PYBIND11_TYPE_CASTER

Permits using macro outside of pybind11::detail

* fixup! review
2022-02-25 13:25:23 -08:00
Ralf W. Grosse-Kunstleve
be43439670 Merge branch 'master' into sh_merge_master 2022-02-23 15:47:03 -08:00
kururu002
da15bb206c
Cast bytearray to string (#3707)
* Add bytearray to string cast, testcase and rename load_bytes to load_raw

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

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

* New bytearray test case and convert failure to pybind11_fail

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

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

* Fix merge comments

* Actually fix merge comments

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

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

* Assert early if AsString fails

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Porras Huang <pohuang@jackx-vm-1.nvidia.com>
2022-02-23 18:21:03 -05:00
StarQTius
9aa676d38d
fix: clear local internals after finalizing interpreter #2101 (#3744)
* Clear local internals after finalizing interpreter

* Add descriptive comments

* [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>
2022-02-20 08:00:29 -08:00
Ralf W. Grosse-Kunstleve
97862b126a
Using #undef _ before "#include <catch.hpp>", as suggested by @henryiii (#3747) 2022-02-18 11:51:56 -08:00
Peter Hawkins
44596bc4ee
Fix exception handling when pybind11::weakref() fails. (#3739)
* Clear Python error state if pybind11::weakref() fails.

The weakref() constructor calls pybind11_fail() without clearing any
Python interpreter error state. If a client catches the C++ exception
thrown by pybind11_fail(), the Python interpreter will be left in an
error state.

* Add test case for failing to create weakref

* Add Debug asserts for pybind11 fail

* Make error handling more pythonic

* Does this fix PyPy?

* Adapt test to PyPy differences

* Simplify test to remove redundancy

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-02-18 14:12:00 -05:00
Ralf W. Grosse-Kunstleve
bc2cec0783 Merge branch 'master' into sh_merge_master 2022-02-16 07:15:34 -08:00
Ralf W. Grosse-Kunstleve
c14170a787
Removing // clang-format off - on directives from test_pickling.cpp (#3738) 2022-02-15 11:51:17 -08:00
Henry Schreiner
a25d40c7bc
tests: use 'build' in tests instead of running setup.py (#3734)
Co-authored-by: Anderson Bravalheri <andersonbravalheri@gmail.com>

Co-authored-by: Anderson Bravalheri <andersonbravalheri@gmail.com>
2022-02-15 00:32:58 -05:00
Ralf W. Grosse-Kunstleve
05c8b9b7a8 Automatic pre-commit run --all-files and clang-tidy changes (NO manual changes). 2022-02-14 19:00:40 -08:00
Ralf W. Grosse-Kunstleve
d5e302ce46 Removing uses of env.PY2 and env.PY (no longer available).
smart_holder_type_casters.h tweaks:
    * Removing MSVC 2015 workaround.
    * Manually adding braces to pre-empt clang-tidy issue (involving `#ifdef`).
    * Removing `// clang-format off` & `on`.
    * One manual line break (moving comment above line).

Adding mypy type information for ubench/*.py
2022-02-14 18:51:58 -08:00
Ralf W. Grosse-Kunstleve
e1751c04f0 Merge branch 'master' into sh_merge_master_after_clang-format_etc
First pass manually resolving the many merge conflicts.
2022-02-14 14:36:08 -08:00
Ralf W. Grosse-Kunstleve
a97e9d8cac
Dropping MSVC 2015 (#3722)
* Changing `_MSC_VER` guard to `< 1910` (dropping MSVC 2015).

* Removing MSVC 2015 from ci.yml, and .appveyor.yml entirely.

* Bringing back .appveyor.yml from master.

* appveyor Visual Studio 2017

* 1st manual pass, builds & tests with unix_clang, before pre-commit.

* After clang-format (via pre-commit).

* Manual pass looking for "2015", builds & tests with unix_clang, before pre-commit.

* Backtracking for include/pybind11 changes in previous commit.

git checkout d07865846c include/pybind11/attr.h include/pybind11/detail/common.h include/pybind11/functional.h

--------------------

CI #4160 errors observed:

2a26873727
https://github.com/pybind/pybind11/runs/5168332130?check_suite_focus=true

$ grep ' error C' *.txt | sed 's/2022-02-12[^ ]*//' | sed 's/^[0-9][0-9]*//' | sed 's/^.*\.txt: //' | sort | uniqD:\a\pybind11\pybind11\include\pybind11\cast.h(1364,1): error C2752: 'pybind11::detail::type_caster<Eigen::Ref<Eigen::Vector3f,0,pybind11::EigenDStride>,void>': more than one partial specialization matches the template argument list [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]

d:\a\pybind11\pybind11\include\pybind11\detail/common.h(1023): error C2737: 'pybind11::overload_cast': 'constexpr' object must be initialized [D:\a\pybind11\pybind11\build\tests\cross_module_gil_utils.vcxproj]
d:\a\pybind11\pybind11\include\pybind11\detail/common.h(1023): error C2737: 'pybind11::overload_cast': 'constexpr' object must be initialized [D:\a\pybind11\pybind11\build\tests\pybind11_cross_module_tests.vcxproj]
d:\a\pybind11\pybind11\include\pybind11\detail/common.h(1023): error C2737: 'pybind11::overload_cast': 'constexpr' object must be initialized [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]
d:\a\pybind11\pybind11\include\pybind11\detail/common.h(1023): error C2737: 'pybind11::overload_cast': 'constexpr' object must be initialized [D:\a\pybind11\pybind11\build\tests\test_embed\external_module.vcxproj]
D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]
D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]

$ grep ': error C2737' *.txt | sed 's/^.*MSVC//' | sed 's/___.*//' | sort | uniq

_2017

$ grep ': error C2752' *.txt

3______3.8_____MSVC_2019_____x86_-DCMAKE_CXX_STANDARD=17.txt:2022-02-12T16:12:45.9921122Z D:\a\pybind11\pybind11\include\pybind11\cast.h(1364,1): error C2752: 'pybind11::detail::type_caster<Eigen::Ref<Eigen::Vector3f,0,pybind11::EigenDStride>,void>': more than one partial specialization matches the template argument list [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]

$ grep ': fatal error C1001:' *.txt

10______pypy-3.8-v7.3.7_____windows-2022_____x64.txt:2022-02-12T16:12:56.3163683Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
1______3.6_____MSVC_2019_____x86.txt:2022-02-12T16:12:47.6774625Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]
16______3.6_____windows-latest_____x64_-DPYBIND11_FINDPYTHON=ON.txt:2022-02-12T16:12:27.0556151Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
17______3.9_____windows-2019_____x64.txt:2022-02-12T16:12:30.3822566Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
2______3.7_____MSVC_2019_____x86.txt:2022-02-12T16:12:38.7018911Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\build\tests\pybind11_tests.vcxproj]
6______3.6_____windows-2022_____x64.txt:2022-02-12T16:12:00.4513642Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
7______3.9_____windows-2022_____x64.txt:2022-02-12T16:11:43.6306160Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
8______3.10_____windows-2022_____x64.txt:2022-02-12T16:11:49.9589644Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]
9______pypy-3.7-v7.3.7_____windows-2022_____x64.txt:2022-02-12T16:11:53.7912112Z D:\a\pybind11\pybind11\include\pybind11\detail/common.h(624): fatal error C1001: Internal compiler error. [D:\a\pybind11\pybind11\tests\pybind11_tests.vcxproj]

* common.h: is_template_base_of

* Re-applying 4 changes from 2a26873727 that work universally.

* `overload_cast = {};` only for MSVC 2017 and Clang 5

* Refining condition for using is_template_base_of workaround.

* Undoing MSVC 2015 workaround in test_constants_and_functions.cpp

* CentOS7: silence_unused_warnings

* Tweaks in response to reviews.

* Adding windows-2022 C++20

* Trying another way of adding windows-2022 C++20
2022-02-14 11:36:22 -08:00
Henry Schreiner
522c59ceb2
chore: drop Python 3.5 (#3719)
* chore: drop Python 3.5 support

* chore: more fstrings with flynt's help

* ci: drop Python 3.5

* chore: bump dependency versions

* docs: touch up py::args

* tests: remove deprecation warning

* Ban smartquotes

* Very minor tweaks (by-product of reviewing PR #3719).

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
2022-02-11 19:06:16 -05:00
Chris Ohk
1a432b426f
docs: Correct minor typos (#3721) 2022-02-11 10:42:48 -05:00
Ralf W. Grosse-Kunstleve
6493f496e3
Python 2 removal part 1: tests (C++ code is intentionally ~untouched) (#3688)
* `#error BYE_BYE_GOLDEN_SNAKE`

* Removing everything related to 2.7 from ci.yml

* Commenting-out Centos7

* Removing `PYTHON: 27` from .appveyor.yml

* "PY2" removal, mainly from tests. C++ code is not touched.

* Systematic removal of `u` prefix from `u"..."` and `u'...'` literals. Collateral cleanup of a couple minor other things.

* Cleaning up around case-insensitive hits for `[^a-z]py.*2` in tests/.

* Removing obsolete Python 2 mention in compiling.rst

* Proper `#error` for Python 2.

* Using PY_VERSION_HEX to guard `#error "PYTHON 2 IS NO LONGER SUPPORTED.`

* chore: bump pre-commit

* style: run pre-commit for pyupgrade 3+

* tests: use sys.version_info, not PY

* chore: more Python 2 removal

* Uncommenting Centos7 block (PR #3691 showed that it is working again).

* Update pre-commit hooks

* Fix pre-commit hook

* refactor: remove Python 2 from CMake

* refactor: remove Python 2 from setup code

* refactor: simplify, better static typing

* feat: fail with nice messages

* refactor: drop Python 2 C++ code

* docs: cleanup for Python 3

* revert: intree

revert: intree

* docs: minor touchup to py2 statement

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-02-10 18:28:08 -08:00
Ralf W. Grosse-Kunstleve
ec24786eab
Fully-automatic clang-format with include reordering (#3713)
* chore: add clang-format

* Removing check-style (Classic check-style)

Ported from @henryiii's 53056b1b0e

* Automatic clang-format changes (NO manual changes).

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-02-10 12:17:07 -08:00
Ralf W. Grosse-Kunstleve
e96221beff
Final manual curation in preparation for global clang-formating (#3712)
* Manual line breaks to pre-empt undesired `clang-format`ing.

Informed by work under https://github.com/pybind/pybind11/pull/3683:

60b7eb410f

59572e6559

* Manual curation of clang-format diffs involving source code comments.

Very labor-intensive and dull.

* Pulling .clang-format change from @henryiii's 9057962d40

* Adding commonly used .clang-format `CommentPragmas:`

* Ensure short lambdas are allowed

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
2022-02-10 11:42:03 -08:00
Aaron Gokaslan
d6c66d25bb
chore(clang-tidy): Add clang-tidy rules: prefer-member-initializer and optin.performance.Padding (#3716)
* Add clang-tidy prefer-member-initializer

* Fix clang-tdy config

* Fix incorrect change

* Fix sorting of .clang-tidy
2022-02-10 09:45:46 -08:00
Aaron Gokaslan
dc9803cef2
Add missing clang-tidy fixes (#3715) 2022-02-10 09:23:15 -08:00
Ralf W. Grosse-Kunstleve
abc38690dc
Manually applying two clang-format changes that need fix-ups for clang-tidy. (#3705) 2022-02-09 06:32:41 -08:00
Ralf W. Grosse-Kunstleve
7769e7719c
clang-tidy readability-qualified-auto (#3702)
* Adding readability-qualified-auto to .clang-tidy

Ported from @henryiii's 287527f705

* fix: support Python < 3.6

Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-02-09 06:24:57 -08:00
Ralf W. Grosse-Kunstleve
ddbc74c674 Adding .clang-tidy readability-braces-around-statements option.
clang-tidy automatic changes. NO manual changes.
2022-02-08 13:02:20 -08:00
Michał Górny
96b943be1d
tests: update catch to 2.13.5 to fix glibc 2.34 failures (#3679)
* Download catch for MinGw

* Fix rest of MinGW

* fix: update catch to 2.13.5 to fix glibc 2.34 failures

Update the downloaded Catch version to 2.13.5, in order to fix build
failure on glibc 2.34:

```
In file included from /usr/include/signal.h:328,
                 from /tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:8030,
                 from /tmp/pybind11/tests/test_embed/catch.cpp:13:
/tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10818:58: error: call to non-‘constexpr’ function ‘long int sysconf(int)’
10818 |     static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
      |                                                          ^~~~~~~~~~~
In file included from /usr/include/python3.9/Python.h:36,
                 from /tmp/pybind11/include/pybind11/detail/common.h:215,
                 from /tmp/pybind11/include/pybind11/pytypes.h:12,
                 from /tmp/pybind11/include/pybind11/cast.h:13,
                 from /tmp/pybind11/include/pybind11/attr.h:13,
                 from /tmp/pybind11/include/pybind11/pybind11.h:13,
                 from /tmp/pybind11/include/pybind11/embed.h:12,
                 from /tmp/pybind11/tests/test_embed/catch.cpp:4:
/usr/include/unistd.h:640:17: note: ‘long int sysconf(int)’ declared here
  640 | extern long int sysconf (int __name) __THROW;
      |                 ^~~~~~~
In file included from /tmp/pybind11/tests/test_embed/catch.cpp:13:
/tmp/pybind11/.nox/tests-3-9/tmp/tests/catch/catch.hpp:10877:45: error: size of array ‘altStackMem’ is not an integral constant-expression
10877 |     char FatalConditionHandler::altStackMem[sigStackSize] = {};
      |                                             ^~~~~~~~~~~~
```

The newest Catch version cannot be used yet because of regression:
https://github.com/catchorg/Catch2/pull/2364

* fix: add option for _ check, only define on pybind11

* Revert "fix: add option for _ check, only define on pybind11"

This reverts commit 86817db488.

* fix: only undef _ for catch cpp creation.

Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
2022-02-05 23:53:02 -05:00
Ralf W. Grosse-Kunstleve
4070a64f86 Merge branch 'master' into sh_merge_master 2022-02-03 15:07:04 -08:00
Michał Górny
1d3b04e805
test: Strip whitespace when comparing numpy dtypes for 1.22 compat (#3682)
* test: Strip whitespace when comparing numpy dtypes for 1.22 compat

Strip whitespace when comparing numpy dtype str() in order to preserve
test compatibility with both numpy 1.22 and older versions whose output
differ by whitespace.

Fixes #3680

* [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>
2022-02-03 12:29:46 -05:00
Aaron Gokaslan
3a8d92308d
Fix caster optimization regression introduced in #3650 (#3659)
* Fix optimization bug introduced in #3650

* Add simple Python extension test for MVF

* Improve comments

* Clarify comment

* Clarify another comment

* Add test docstring

* Fix typo
2022-01-31 12:19:48 -05:00
Ralf W. Grosse-Kunstleve
aa4fe8e4ff Merge branch 'master' into sh_merge_master 2022-01-26 19:08:58 -08:00
Dustin Spicuzza
ec81e8e778
Propagate py::multiple_inheritance to all children (#3650)
* Add tests demonstrating smart_holder issues with multiple inheritance

* Propagate C++ multiple inheritance markers to all children

- Makes py::multiple_inheritance only needed in base classes hidden from pybind11
2022-01-26 17:03:52 -08:00
Xiaofei Wang
93a376a40a
[smart_holder] Add missing test case to CMakeLists.txt (#3645)
* Add missing test case to CMakeLists.txt

* Fix warnings

* Fix Clangtidy
2022-01-25 16:43:11 -08:00
Xiaofei Wang
da058a2904
[Smart holder] Support void pointer capsules (#3633)
* Make smart holder type casters support void pointer capsules.

* Fix warnings

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

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

* Fix checks

* Fix check failures under CentOS

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

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

* Remove unused regex module

* Resolve comments

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

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

* Resolve comments

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

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

* Fix clangtidy

* Resolve comments

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-25 13:29:54 -08:00