From 1a8603e4792315d1eabcbaaa4b286a3a98963b0d Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 24 Apr 2022 13:50:29 -0400 Subject: [PATCH 01/12] ci: dependabot major versions for official actions (#3888) * ci: dependabot major versions for official actions * style: use extend-select for flake8 --- .github/dependabot.yml | 9 ++------- setup.cfg | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 73273365c..d8d1eed8c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,10 +7,5 @@ updates: interval: "daily" ignore: # Official actions have moving tags like v1 - # that are used, so they don't need updates here - - dependency-name: "actions/checkout" - - dependency-name: "actions/setup-python" - - dependency-name: "actions/cache" - - dependency-name: "actions/upload-artifact" - - dependency-name: "actions/download-artifact" - - dependency-name: "actions/labeler" + - dependency-name: "actions/*" + update-types: ["version-update:semver-minor", "version-update:semver-patch"] diff --git a/setup.cfg b/setup.cfg index 11b4fde8f..4fd1e7a6f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,4 +46,4 @@ max-line-length = 120 show_source = True exclude = .git, __pycache__, build, dist, docs, tools, venv extend-ignore = E203, E722, B950 -select = C,E,F,N,W,B,B9 +extend-select = B9 From b58b772b4632dca24014fee0dc193c41a448ae5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 24 Apr 2022 14:40:58 -0400 Subject: [PATCH 02/12] chore(deps): bump actions/setup-python from 2 to 3 (#3895) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/configure.yml | 2 +- .github/workflows/format.yml | 2 +- .github/workflows/pip.yml | 6 +++--- .github/workflows/upstream.yml | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e018fb7f..14e8adea7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} @@ -680,7 +680,7 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v3 - name: Install Doxygen run: sudo apt-get install -y doxygen librsvg2-bin # Changed to rsvg-convert in 20.04 @@ -728,7 +728,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} architecture: x86 @@ -781,7 +781,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} architecture: x86 @@ -829,7 +829,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python ${{ matrix.python }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python }} diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml index 55be5bd34..23cc28376 100644 --- a/.github/workflows/configure.yml +++ b/.github/workflows/configure.yml @@ -40,7 +40,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python 3.7 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: 3.7 architecture: ${{ matrix.arch }} diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 46140fe0c..d46f81442 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v3 - name: Add matchers run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" - uses: pre-commit/action@v2.0.3 diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 7a5443d14..b76d0c8bd 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -27,7 +27,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup 🐍 3.6 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: 3.6 @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup 🐍 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: 3.8 @@ -90,7 +90,7 @@ jobs: needs: [packaging] steps: - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v3 # Downloads all to directories matching the artifact names - uses: actions/download-artifact@v2 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 138c9ad29..8dc860f2b 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Python 3.11 - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: "3.11-dev" From e79293cf2fd68578ce63c08a8663397b3af9d807 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 24 Apr 2022 14:41:09 -0400 Subject: [PATCH 03/12] chore(deps): bump actions/cache from 2 to 3 (#3898) Bumps [actions/cache](https://github.com/actions/cache) from 2 to 3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14e8adea7..9a99be3bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: - name: Cache wheels if: runner.os == 'macOS' - uses: actions/cache@v2 + uses: actions/cache@v3 with: # This path is specific to macOS - we really only need it for PyPy NumPy wheels # See https://github.com/actions/cache/blob/master/examples.md#python---pip @@ -205,7 +205,7 @@ jobs: - name: Valgrind cache if: matrix.valgrind - uses: actions/cache@v2 + uses: actions/cache@v3 id: cache-valgrind with: path: valgrind From 2a7cb008acbf7a1942a6270b014bdf86886ed6f1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 24 Apr 2022 14:41:23 -0400 Subject: [PATCH 04/12] chore(deps): bump actions/download-artifact from 2 to 3 (#3897) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pip.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index b76d0c8bd..7b0a73a63 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -93,7 +93,7 @@ jobs: - uses: actions/setup-python@v3 # Downloads all to directories matching the artifact names - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 - name: Publish standard package uses: pypa/gh-action-pypi-publish@v1.5.0 From 82455a41fdc9cabf6a0eeba2071dc8a0c8cac4c1 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sun, 24 Apr 2022 14:46:39 -0400 Subject: [PATCH 05/12] Minor opt to cache tuple casting (#3894) --- include/pybind11/numpy.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 2713e13a8..b8ba2259f 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -647,8 +647,9 @@ private: for (auto field : attr("fields").attr("items")()) { auto spec = field.cast(); auto name = spec[0].cast(); - auto format = spec[1].cast()[0].cast(); - auto offset = spec[1].cast()[1].cast(); + auto spec_fo = spec[1].cast(); + auto format = spec_fo[0].cast(); + auto offset = spec_fo[1].cast(); if ((len(name) == 0u) && format.kind() == 'V') { continue; } From be4a634c675fc55db6da595c322f2ca947096862 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 24 Apr 2022 16:49:13 -0400 Subject: [PATCH 06/12] chore(deps): bump actions/checkout from 2 to 3 (#3896) Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 30 +++++++++++++++--------------- .github/workflows/configure.yml | 2 +- .github/workflows/format.yml | 4 ++-- .github/workflows/pip.yml | 4 ++-- .github/workflows/upstream.yml | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a99be3bb..aeceaee2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v3 @@ -192,7 +192,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python-version }} (deadsnakes) uses: deadsnakes/action@v2.1.1 @@ -285,7 +285,7 @@ jobs: container: "silkeh/clang:${{ matrix.clang }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Add wget and python3 run: apt-get update && apt-get install -y python3-dev python3-numpy python3-pytest libeigen3-dev @@ -319,7 +319,7 @@ jobs: container: nvidia/cuda:11.0-devel-ubuntu20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # tzdata will try to ask for the timezone, so set the DEBIAN_FRONTEND - name: Install 🐍 3 @@ -343,7 +343,7 @@ jobs: # container: centos:8 # # steps: -# - uses: actions/checkout@v2 +# - uses: actions/checkout@v3 # # - name: Add Python 3 and a few requirements # run: yum update -y && yum install -y git python3-devel python3-numpy python3-pytest make environment-modules @@ -386,7 +386,7 @@ jobs: container: centos:7 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Add Python 3 and a few requirements run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 @@ -447,7 +447,7 @@ jobs: container: "gcc:${{ matrix.gcc }}" steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Add Python 3 run: apt-get update; apt-get install -y python3-dev python3-numpy python3-pytest python3-pip libeigen3-dev @@ -489,7 +489,7 @@ jobs: name: "🐍 3 • ICC latest • x64" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Add apt repo run: | @@ -592,7 +592,7 @@ jobs: container: "quay.io/centos/centos:${{ matrix.centos }}" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Add Python 3 run: yum update -y && yum install -y python3-devel gcc-c++ make git @@ -635,7 +635,7 @@ jobs: container: i386/debian:buster steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Install requirements run: | @@ -678,7 +678,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-python@v3 @@ -725,7 +725,7 @@ jobs: runs-on: windows-2019 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v3 @@ -778,7 +778,7 @@ jobs: runs-on: windows-2019 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v3 @@ -826,7 +826,7 @@ jobs: runs-on: windows-2022 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python ${{ matrix.python }} uses: actions/setup-python@v3 @@ -889,7 +889,7 @@ jobs: mingw-w64-${{matrix.env}}-boost mingw-w64-${{matrix.env}}-catch - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Configure C++11 # LTO leads to many undefined reference like diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml index 23cc28376..aa2485ac0 100644 --- a/.github/workflows/configure.yml +++ b/.github/workflows/configure.yml @@ -37,7 +37,7 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python 3.7 uses: actions/setup-python@v3 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index d46f81442..5eb228a70 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -20,7 +20,7 @@ jobs: name: Format runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - name: Add matchers run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" @@ -36,7 +36,7 @@ jobs: runs-on: ubuntu-latest container: silkeh/clang:12 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install requirements run: apt-get update && apt-get install -y python3-dev python3-pytest diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 7b0a73a63..6e7afa385 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -24,7 +24,7 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup 🐍 3.6 uses: actions/setup-python@v3 @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup 🐍 3.8 uses: actions/setup-python@v3 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index 8dc860f2b..174dc2496 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -19,7 +19,7 @@ jobs: if: "contains(github.event.pull_request.labels.*.name, 'python dev')" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python 3.11 uses: actions/setup-python@v3 From 03252067db057777db75c2e5bcf0e69013b919ec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 24 Apr 2022 16:49:41 -0400 Subject: [PATCH 07/12] chore(deps): bump actions/upload-artifact from 2 to 3 (#3899) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pip.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 6e7afa385..1d9a35604 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -69,13 +69,13 @@ jobs: run: twine check dist/* - name: Save standard package - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: standard path: dist/pybind11-* - name: Save global package - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: global path: dist/pybind11_global-* From 9bc270443068c90298c0220cd866fbf9ea1bb589 Mon Sep 17 00:00:00 2001 From: Ed Catmur Date: Sun, 24 Apr 2022 22:39:47 +0100 Subject: [PATCH 08/12] 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, std::list and std::valarray. Extracted from #3886. --- tests/test_stl.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_stl.py b/tests/test_stl.py index 3dc55230a..975860b85 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -14,6 +14,7 @@ def test_vector(doc): assert m.cast_bool_vector() == [True, False] assert m.load_bool_vector([True, False]) + assert m.load_bool_vector(tuple([True, False])) assert doc(m.cast_vector) == "cast_vector() -> List[int]" assert doc(m.load_vector) == "load_vector(arg0: List[int]) -> bool" @@ -36,6 +37,7 @@ def test_array(doc): lst = m.cast_array() assert lst == [1, 2] assert m.load_array(lst) + assert m.load_array(tuple(lst)) assert doc(m.cast_array) == "cast_array() -> List[int[2]]" assert doc(m.load_array) == "load_array(arg0: List[int[2]]) -> bool" @@ -46,6 +48,7 @@ def test_valarray(doc): lst = m.cast_valarray() assert lst == [1, 4, 9] assert m.load_valarray(lst) + assert m.load_valarray(tuple(lst)) assert doc(m.cast_valarray) == "cast_valarray() -> List[int]" assert doc(m.load_valarray) == "load_valarray(arg0: List[int]) -> bool" From 75007dda72ad4508064c1f080394eae50d3a61ee Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 26 Apr 2022 15:49:24 -0400 Subject: [PATCH 09/12] chore: rule of 3 for strdup guard (#3905) --- include/pybind11/pybind11.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index ce05b6e4e..e828f725d 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -312,6 +312,10 @@ protected: // along the way. class strdup_guard { public: + strdup_guard() = default; + strdup_guard(const strdup_guard &) = delete; + strdup_guard &operator=(const strdup_guard &) = delete; + ~strdup_guard() { for (auto *s : strings) { std::free(s); From f0b9f755e465532f90ae6e696bdd7fa4e9d589ce Mon Sep 17 00:00:00 2001 From: Michael Voznesensky Date: Mon, 2 May 2022 12:30:19 -0700 Subject: [PATCH 10/12] 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 --- include/pybind11/attr.h | 6 ++- include/pybind11/cast.h | 51 ++++++++++++---------- include/pybind11/detail/common.h | 7 +++ include/pybind11/detail/type_caster_base.h | 31 +++++++------ include/pybind11/gil.h | 6 +-- include/pybind11/pybind11.h | 9 ++-- tests/pybind11_tests.cpp | 6 +-- tests/test_methods_and_attributes.cpp | 6 +-- tests/test_methods_and_attributes.py | 20 ++++----- tests/test_pytypes.py | 6 +-- 10 files changed, 82 insertions(+), 66 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 38139afa3..14600e9bb 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -10,6 +10,7 @@ #pragma once +#include "detail/common.h" #include "cast.h" #include @@ -477,7 +478,7 @@ struct process_attribute : process_attribute_default { } if (!a.value) { -#if !defined(NDEBUG) +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) std::string descr("'"); if (a.name) { descr += std::string(a.name) + ": "; @@ -498,7 +499,8 @@ struct process_attribute : process_attribute_default { #else pybind11_fail("arg(): could not convert default argument " "into a Python object (type not registered yet?). " - "Compile in debug mode for more information."); + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " + "more information."); #endif } r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none); diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index e8128710e..22d2dba4c 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -777,8 +777,9 @@ protected: return true; } throw cast_error("Unable to cast from non-held to held instance (T& to Holder) " -#if defined(NDEBUG) - "(compile in debug mode for type information)"); +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) + "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for " + "type information)"); #else "of type '" + type_id() + "''"); @@ -1001,9 +1002,9 @@ struct return_value_policy_override< template type_caster &load_type(type_caster &conv, const handle &handle) { if (!conv.load(handle, true)) { -#if defined(NDEBUG) - throw cast_error( - "Unable to cast Python instance to C++ type (compile in debug mode for details)"); +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) + throw cast_error("Unable to cast Python instance to C++ type (#define " + "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); #else throw cast_error("Unable to cast Python instance of type " + (std::string) str(type::handle_of(handle)) + " to C++ type '" @@ -1068,10 +1069,10 @@ inline void handle::cast() const { template detail::enable_if_t::value, T> move(object &&obj) { if (obj.ref_count() > 1) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) throw cast_error( "Unable to cast Python instance to C++ rvalue: instance has multiple references" - " (compile in debug mode for details)"); + " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); #else throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj)) + " instance to C++ " + type_id() @@ -1172,10 +1173,10 @@ PYBIND11_NAMESPACE_END(detail) // The overloads could coexist, i.e. the #if is not strictly speaking needed, // but it is an easy minor optimization. -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) inline cast_error cast_error_unable_to_convert_call_arg() { - return cast_error( - "Unable to convert call argument to Python object (compile in debug mode for details)"); + return cast_error("Unable to convert call argument to Python object (#define " + "PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); } #else inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name, @@ -1197,7 +1198,7 @@ tuple make_tuple(Args &&...args_) { detail::make_caster::cast(std::forward(args_), policy, nullptr))...}}; for (size_t i = 0; i < args.size(); i++) { if (!args[i]) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) throw cast_error_unable_to_convert_call_arg(); #else std::array argtypes{{type_id()...}}; @@ -1249,7 +1250,7 @@ private: : arg(base), value(reinterpret_steal(detail::make_caster::cast( std::forward(x), return_value_policy::automatic, {}))), descr(descr) -#if !defined(NDEBUG) +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) , type(type_id()) #endif @@ -1289,7 +1290,7 @@ public: object value; /// The (optional) description of the default value const char *descr; -#if !defined(NDEBUG) +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) /// The C++ type name of the default value (only available when compiled in debug mode) std::string type; #endif @@ -1487,7 +1488,7 @@ private: auto o = reinterpret_steal( detail::make_caster::cast(std::forward(x), policy, {})); if (!o) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) throw cast_error_unable_to_convert_call_arg(); #else throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()), @@ -1505,21 +1506,21 @@ private: void process(list & /*args_list*/, arg_v a) { if (!a.name) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) nameless_argument_error(); #else nameless_argument_error(a.type); #endif } if (m_kwargs.contains(a.name)) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) multiple_values_error(); #else multiple_values_error(a.name); #endif } if (!a.value) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) throw cast_error_unable_to_convert_call_arg(); #else throw cast_error_unable_to_convert_call_arg(a.name, a.type); @@ -1534,7 +1535,7 @@ private: } for (auto k : reinterpret_borrow(kp)) { if (m_kwargs.contains(k.first)) { -#if defined(NDEBUG) +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) multiple_values_error(); #else multiple_values_error(str(k.first)); @@ -1545,9 +1546,10 @@ private: } [[noreturn]] static void nameless_argument_error() { - throw type_error("Got kwargs without a name; only named arguments " - "may be passed via py::arg() to a python function call. " - "(compile in debug mode for details)"); + throw type_error( + "Got kwargs without a name; only named arguments " + "may be passed via py::arg() to a python function call. " + "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); } [[noreturn]] static void nameless_argument_error(const std::string &type) { throw type_error("Got kwargs without a name of type '" + type @@ -1555,8 +1557,9 @@ private: "arguments may be passed via py::arg() to a python function call. "); } [[noreturn]] static void multiple_values_error() { - throw type_error("Got multiple values for keyword argument " - "(compile in debug mode for details)"); + throw type_error( + "Got multiple values for keyword argument " + "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); } [[noreturn]] static void multiple_values_error(const std::string &name) { @@ -1603,7 +1606,7 @@ unpacking_collector collect_arguments(Args &&...args) { template template object object_api::operator()(Args &&...args) const { -#ifndef NDEBUG +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) if (!PyGILState_Check()) { pybind11_fail("pybind11::object_api<>::operator() PyGILState_Check() failure."); } diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index a130ebea0..9355ecfda 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -1157,5 +1157,12 @@ constexpr inline bool silence_msvc_c4127(bool cond) { return cond; } # define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__ #endif +// Pybind offers detailed error messages by default for all builts that are debug (through the +// negation of ndebug). This can also be manually enabled by users, for any builds, through +// defining PYBIND11_DETAILED_ERROR_MESSAGES. +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(NDEBUG) +# define PYBIND11_DETAILED_ERROR_MESSAGES +#endif + PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 5b2ec8e1e..a7b977132 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -394,15 +394,16 @@ instance::get_value_and_holder(const type_info *find_type /*= nullptr default in return value_and_holder(); } -#if defined(NDEBUG) - pybind11_fail("pybind11::detail::instance::get_value_and_holder: " - "type is not a pybind11 base of the given instance " - "(compile in debug mode for type details)"); -#else +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) pybind11_fail("pybind11::detail::instance::get_value_and_holder: `" + get_fully_qualified_tp_name(find_type->type) + "' is not a pybind11 base of the given `" + get_fully_qualified_tp_name(Py_TYPE(this)) + "' instance"); +#else + pybind11_fail( + "pybind11::detail::instance::get_value_and_holder: " + "type is not a pybind11 base of the given instance " + "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for type details)"); #endif } @@ -612,14 +613,15 @@ public: if (copy_constructor) { valueptr = copy_constructor(src); } else { -#if defined(NDEBUG) - throw cast_error("return_value_policy = copy, but type is " - "non-copyable! (compile in debug mode for details)"); -#else +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) std::string type_name(tinfo->cpptype->name()); detail::clean_type_id(type_name); throw cast_error("return_value_policy = copy, but type " + type_name + " is non-copyable!"); +#else + throw cast_error("return_value_policy = copy, but type is " + "non-copyable! (#define PYBIND11_DETAILED_ERROR_MESSAGES or " + "compile in debug mode for details)"); #endif } wrapper->owned = true; @@ -631,15 +633,16 @@ public: } else if (copy_constructor) { valueptr = copy_constructor(src); } else { -#if defined(NDEBUG) - throw cast_error("return_value_policy = move, but type is neither " - "movable nor copyable! " - "(compile in debug mode for details)"); -#else +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) std::string type_name(tinfo->cpptype->name()); detail::clean_type_id(type_name); throw cast_error("return_value_policy = move, but type " + type_name + " is neither movable nor copyable!"); +#else + throw cast_error("return_value_policy = move, but type is neither " + "movable nor copyable! " + "(#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in " + "debug mode for details)"); #endif } wrapper->owned = true; diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 446f4620b..a0b5de151 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -62,7 +62,7 @@ public: if (!tstate) { tstate = PyThreadState_New(internals.istate); -# if !defined(NDEBUG) +# if defined(PYBIND11_DETAILED_ERROR_MESSAGES) if (!tstate) { pybind11_fail("scoped_acquire: could not create thread state!"); } @@ -84,7 +84,7 @@ public: PYBIND11_NOINLINE void dec_ref() { --tstate->gilstate_counter; -# if !defined(NDEBUG) +# if defined(PYBIND11_DETAILED_ERROR_MESSAGES) if (detail::get_thread_state_unchecked() != tstate) { pybind11_fail("scoped_acquire::dec_ref(): thread state must be current!"); } @@ -93,7 +93,7 @@ public: } # endif if (tstate->gilstate_counter == 0) { -# if !defined(NDEBUG) +# if defined(PYBIND11_DETAILED_ERROR_MESSAGES) if (!release) { pybind11_fail("scoped_acquire::dec_ref(): internal error!"); } diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index e828f725d..cd86152e5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -370,7 +370,7 @@ protected: rec->is_constructor = (std::strcmp(rec->name, "__init__") == 0) || (std::strcmp(rec->name, "__setstate__") == 0); -#if !defined(NDEBUG) && !defined(PYBIND11_DISABLE_NEW_STYLE_INIT_WARNING) +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) && !defined(PYBIND11_DISABLE_NEW_STYLE_INIT_WARNING) if (rec->is_constructor && !rec->is_new_style_constructor) { const auto class_name = detail::get_fully_qualified_tp_name((PyTypeObject *) rec->scope.ptr()); @@ -518,8 +518,9 @@ protected: if (chain->is_method != rec->is_method) { pybind11_fail( "overloading a method with both static and instance methods is not supported; " -#if defined(NDEBUG) - "compile in debug mode for more details" +#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more " + "details" #else "error while attempting to bind " + std::string(rec->is_method ? "instance" : "static") + " method " @@ -906,7 +907,7 @@ protected: // 5. Put everything in a vector. Not technically step 5, we've been building it // in `call.args` all along. -#if !defined(NDEBUG) +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) if (call.args.size() != func.nargs || call.args_convert.size() != func.nargs) { pybind11_fail("Internal error: function call dispatcher inserted wrong number " "of arguments!"); diff --git a/tests/pybind11_tests.cpp b/tests/pybind11_tests.cpp index d9b88fcc2..3c0469915 100644 --- a/tests/pybind11_tests.cpp +++ b/tests/pybind11_tests.cpp @@ -67,10 +67,10 @@ PYBIND11_MODULE(pybind11_tests, m) { bind_ConstructorStats(m); -#if !defined(NDEBUG) - m.attr("debug_enabled") = true; +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) + m.attr("detailed_error_messages_enabled") = true; #else - m.attr("debug_enabled") = false; + m.attr("detailed_error_messages_enabled") = false; #endif py::class_(m, "UserType", "A `py::class_` type for testing") diff --git a/tests/test_methods_and_attributes.cpp b/tests/test_methods_and_attributes.cpp index 10515e26f..815dd5e98 100644 --- a/tests/test_methods_and_attributes.cpp +++ b/tests/test_methods_and_attributes.cpp @@ -361,10 +361,10 @@ TEST_SUBMODULE(methods_and_attributes, m) { // test_bad_arg_default // Issue/PR #648: bad arg default debugging output -#if !defined(NDEBUG) - m.attr("debug_enabled") = true; +#if defined(PYBIND11_DETAILED_ERROR_MESSAGES) + m.attr("detailed_error_messages_enabled") = true; #else - m.attr("debug_enabled") = false; + m.attr("detailed_error_messages_enabled") = false; #endif m.def("bad_arg_def_named", [] { auto m = py::module_::import("pybind11_tests"); diff --git a/tests/test_methods_and_attributes.py b/tests/test_methods_and_attributes.py index 5a95303e1..54597fa78 100644 --- a/tests/test_methods_and_attributes.py +++ b/tests/test_methods_and_attributes.py @@ -216,15 +216,15 @@ def test_metaclass_override(): def test_no_mixed_overloads(): - from pybind11_tests import debug_enabled + from pybind11_tests import detailed_error_messages_enabled with pytest.raises(RuntimeError) as excinfo: m.ExampleMandA.add_mixed_overloads1() assert str( excinfo.value ) == "overloading a method with both static and instance methods is not supported; " + ( - "compile in debug mode for more details" - if not debug_enabled + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + if not detailed_error_messages_enabled else "error while attempting to bind static method ExampleMandA.overload_mixed1" "(arg0: float) -> str" ) @@ -234,8 +234,8 @@ def test_no_mixed_overloads(): assert str( excinfo.value ) == "overloading a method with both static and instance methods is not supported; " + ( - "compile in debug mode for more details" - if not debug_enabled + "#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more details" + if not detailed_error_messages_enabled else "error while attempting to bind instance method ExampleMandA.overload_mixed2" "(self: pybind11_tests.methods_and_attributes.ExampleMandA, arg0: int, arg1: int)" " -> str" @@ -344,16 +344,16 @@ def test_cyclic_gc(): def test_bad_arg_default(msg): - from pybind11_tests import debug_enabled + from pybind11_tests import detailed_error_messages_enabled with pytest.raises(RuntimeError) as excinfo: m.bad_arg_def_named() assert msg(excinfo.value) == ( "arg(): could not convert default argument 'a: UnregisteredType' in function " "'should_fail' into a Python object (type not registered yet?)" - if debug_enabled + if detailed_error_messages_enabled else "arg(): could not convert default argument into a Python object (type not registered " - "yet?). Compile in debug mode for more information." + "yet?). #define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more information." ) with pytest.raises(RuntimeError) as excinfo: @@ -361,9 +361,9 @@ def test_bad_arg_default(msg): assert msg(excinfo.value) == ( "arg(): could not convert default argument 'UnregisteredType' in function " "'should_fail' into a Python object (type not registered yet?)" - if debug_enabled + if detailed_error_messages_enabled else "arg(): could not convert default argument into a Python object (type not registered " - "yet?). Compile in debug mode for more information." + "yet?). #define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for more information." ) diff --git a/tests/test_pytypes.py b/tests/test_pytypes.py index 5c715ada6..c740414ae 100644 --- a/tests/test_pytypes.py +++ b/tests/test_pytypes.py @@ -4,7 +4,7 @@ import sys import pytest import env -from pybind11_tests import debug_enabled +from pybind11_tests import detailed_error_messages_enabled from pybind11_tests import pytypes as m @@ -416,8 +416,8 @@ def test_print(capture): m.print_failure() assert str(excinfo.value) == "Unable to convert call argument " + ( "'1' of type 'UnregisteredType' to Python object" - if debug_enabled - else "to Python object (compile in debug mode for details)" + if detailed_error_messages_enabled + else "to Python object (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)" ) From 287e4f233dcaea92398810b7ff95b7137a96f5a2 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 2 May 2022 12:39:36 -0700 Subject: [PATCH 11/12] 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. --- tests/test_pickling.cpp | 2 ++ tests/test_pickling.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/test_pickling.cpp b/tests/test_pickling.cpp index 9787bd300..e154bc483 100644 --- a/tests/test_pickling.cpp +++ b/tests/test_pickling.cpp @@ -61,6 +61,8 @@ void wrap(py::module m) { } // namespace exercise_trampoline TEST_SUBMODULE(pickling, m) { + m.def("simple_callable", []() { return 20220426; }); + // test_roundtrip class Pickleable { public: diff --git a/tests/test_pickling.py b/tests/test_pickling.py index 52802ace8..12361a661 100644 --- a/tests/test_pickling.py +++ b/tests/test_pickling.py @@ -1,4 +1,5 @@ import pickle +import re import pytest @@ -6,6 +7,20 @@ import env from pybind11_tests import pickling as m +def test_pickle_simple_callable(): + assert m.simple_callable() == 20220426 + if env.PYPY: + serialized = pickle.dumps(m.simple_callable) + deserialized = pickle.loads(serialized) + assert deserialized() == 20220426 + else: + # To document broken behavior: currently it fails universally with + # all C Python versions. + with pytest.raises(TypeError) as excinfo: + pickle.dumps(m.simple_callable) + assert re.search("can.*t pickle .*PyCapsule.* object", str(excinfo.value)) + + @pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"]) def test_roundtrip(cls_name): cls = getattr(m, cls_name) From bdc7dd8c31ee5ab4ec59bbadb0fa64e8059c93b0 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Wed, 4 May 2022 13:02:07 -0400 Subject: [PATCH 12/12] chore: update NVIDIA-PGI CI workflow (#3922) * Update PGI workflow * Remove copy paste typo * ci: fix debian image Co-authored-by: Henry Schreiner --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aeceaee2c..2f295614e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -382,17 +382,17 @@ jobs: # Testing on CentOS 7 + PGI compilers, which seems to require more workarounds centos-nvhpc7: runs-on: ubuntu-latest - name: "🐍 3 • CentOS7 / PGI 20.9 • x64" + name: "🐍 3 • CentOS7 / PGI 22.3 • x64" container: centos:7 steps: - uses: actions/checkout@v3 - name: Add Python 3 and a few requirements - run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 + run: yum update -y && yum install -y epel-release && yum install -y git python3-devel make environment-modules cmake3 yum-utils - name: Install NVidia HPC SDK - run: yum -y install https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc-20-9-20.9-1.x86_64.rpm https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc-2020-20.9-1.x86_64.rpm + run: yum-config-manager --add-repo https://developer.download.nvidia.com/hpc-sdk/rhel/nvhpc.repo && yum -y install nvhpc-22.3 # On CentOS 7, we have to filter a few tests (compiler internal error) # and allow deeper template recursion (not needed on CentOS 8 with a newer @@ -402,7 +402,7 @@ jobs: shell: bash run: | source /etc/profile.d/modules.sh - module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/20.9 + module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/22.3 cmake3 -S . -B build -DDOWNLOAD_CATCH=ON \ -DCMAKE_CXX_STANDARD=11 \ -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \ @@ -635,7 +635,7 @@ jobs: container: i386/debian:buster steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v1 # Required to run inside docker - name: Install requirements run: |