From ab59f45d2ee05b1df299021b62ab1f59a768e285 Mon Sep 17 00:00:00 2001 From: Laramie Leavitt Date: Mon, 11 Apr 2022 10:36:24 -0700 Subject: [PATCH 1/6] Prefer make_caster to type_caster (#3859) --- include/pybind11/cast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 07a56e71f..bead97f91 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -514,7 +514,7 @@ struct type_caster, template struct type_caster::value>> { using StringType = std::basic_string; - using StringCaster = type_caster; + using StringCaster = make_caster; StringCaster str_caster; bool none = false; CharT one_char = 0; From 1b27b744c151bfa2db60566112b4d8307cb05104 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 11 Apr 2022 13:53:30 -0400 Subject: [PATCH 2/6] chore: Make stl_bind take slice as const_ref (#3852) * Make stl_bind take slice as const_ref * Change eval order if * Silence MSVC warning --- include/pybind11/pybind11.h | 3 ++- include/pybind11/stl_bind.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index fa018b509..797c769d7 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1817,7 +1817,8 @@ private: if (holder_ptr) { init_holder_from_existing(v_h, holder_ptr, std::is_copy_constructible()); v_h.set_holder_constructed(); - } else if (inst->owned || detail::always_construct_holder::value) { + } else if (PYBIND11_SILENCE_MSVC_C4127(detail::always_construct_holder::value) + || inst->owned) { new (std::addressof(v_h.holder())) holder_type(v_h.value_ptr()); v_h.set_holder_constructed(); } diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index 3a3e54dd4..22a29b476 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -232,7 +232,7 @@ void vector_modifiers( /// Slicing protocol cl.def( "__getitem__", - [](const Vector &v, slice slice) -> Vector * { + [](const Vector &v, const slice &slice) -> Vector * { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) { @@ -253,7 +253,7 @@ void vector_modifiers( cl.def( "__setitem__", - [](Vector &v, slice slice, const Vector &value) { + [](Vector &v, const slice &slice, const Vector &value) { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) { throw error_already_set(); @@ -281,7 +281,7 @@ void vector_modifiers( cl.def( "__delitem__", - [](Vector &v, slice slice) { + [](Vector &v, const slice &slice) { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) { From e3aa215b020886d648add951186052c619c3cf9d Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 11 Apr 2022 14:03:43 -0400 Subject: [PATCH 3/6] Add perfect forwarding to make_iterator calls (#3860) --- include/pybind11/pybind11.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 797c769d7..97275e40a 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -2403,7 +2403,8 @@ template iterator make_iterator(Type &value, Extra &&...extra) { - return make_iterator(std::begin(value), std::end(value), extra...); + return make_iterator( + std::begin(value), std::end(value), std::forward(extra)...); } /// Makes an iterator over the keys (`.first`) of a stl map-like container supporting @@ -2412,7 +2413,8 @@ template iterator make_key_iterator(Type &value, Extra &&...extra) { - return make_key_iterator(std::begin(value), std::end(value), extra...); + return make_key_iterator( + std::begin(value), std::end(value), std::forward(extra)...); } /// Makes an iterator over the values (`.second`) of a stl map-like container supporting @@ -2421,7 +2423,8 @@ template iterator make_value_iterator(Type &value, Extra &&...extra) { - return make_value_iterator(std::begin(value), std::end(value), extra...); + return make_value_iterator( + std::begin(value), std::end(value), std::forward(extra)...); } template From 088ad4f2987d3da4b1ffab376b2b4812fd7634ef Mon Sep 17 00:00:00 2001 From: Laramie Leavitt Date: Mon, 11 Apr 2022 11:57:05 -0700 Subject: [PATCH 4/6] Cleanup cast_safe specialization (#3861) * Cleanup cast_safe specialization Replace explicit specialization of cast_safe with SFINAE. It's better for SFINAE cases to cover all type-sets rather than mixing SFINAE and explicit specialization. Extracted from #3674 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update cast.h Use detail::none_of<> as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update cast.h Reorder: If TEMP_REF If VOID if (!VOID && !TEMP_REF) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/pybind11/cast.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index bead97f91..e8128710e 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1155,15 +1155,18 @@ enable_if_t::value, T> cast_ref(object &&, // static_assert, even though if it's in dead code, so we provide a "trampoline" to pybind11::cast // that only does anything in cases where pybind11::cast is valid. template -enable_if_t::value, T> cast_safe(object &&o) { - return pybind11::cast(std::move(o)); -} -template enable_if_t::value, T> cast_safe(object &&) { pybind11_fail("Internal error: cast_safe fallback invoked"); } -template <> -inline void cast_safe(object &&) {} +template +enable_if_t>::value, void> cast_safe(object &&) {} +template +enable_if_t, + std::is_same>>::value, + T> +cast_safe(object &&o) { + return pybind11::cast(std::move(o)); +} PYBIND11_NAMESPACE_END(detail) From 9969f3b5b5ccad5524a9dab237b551c0ea6359f4 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 11 Apr 2022 16:54:33 -0400 Subject: [PATCH 5/6] ci: drop win2016 (#3854) * ci: drop dead windows CI jobs * chore: touch up pre-commit Signed-off-by: Henry Schreiner * Update configure.yml * Update configure.yml --- .github/workflows/ci.yml | 49 --------------------------------- .github/workflows/configure.yml | 10 ++----- .pre-commit-config.yaml | 3 +- pyproject.toml | 4 ++- 4 files changed, 7 insertions(+), 59 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2fc52bf2..0e018fb7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -814,55 +814,6 @@ jobs: - name: Python tests run: cmake --build build --config Debug -t pytest - win32-msvc2017: - name: "🐍 ${{ matrix.python }} • MSVC 2017 • x64" - runs-on: windows-2016 - strategy: - fail-fast: false - matrix: - python: - - 3.6 - - 3.7 - std: - - 14 - - include: - - python: 3.7 - std: 17 - args: > - -DCMAKE_CXX_FLAGS="/permissive- /EHsc /GR" - - steps: - - uses: actions/checkout@v2 - - - name: Setup 🐍 ${{ matrix.python }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - - name: Update CMake - uses: jwlawson/actions-setup-cmake@v1.12 - - - name: Prepare env - run: | - python -m pip install -r tests/requirements.txt - - # First build - C++11 mode and inplace - - name: Configure - run: > - cmake -S . -B build - -G "Visual Studio 15 2017" -A x64 - -DPYBIND11_WERROR=ON - -DDOWNLOAD_CATCH=ON - -DDOWNLOAD_EIGEN=ON - -DCMAKE_CXX_STANDARD=${{ matrix.std }} - ${{ matrix.args }} - - - name: Build ${{ matrix.std }} - run: cmake --build build -j 2 - - - name: Run all checks - run: cmake --build build -t check windows-2022: strategy: diff --git a/.github/workflows/configure.yml b/.github/workflows/configure.yml index 66ab0e3d7..55be5bd34 100644 --- a/.github/workflows/configure.yml +++ b/.github/workflows/configure.yml @@ -18,7 +18,7 @@ jobs: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] arch: [x64] - cmake: ["3.21"] + cmake: ["3.23"] include: - runs-on: ubuntu-latest @@ -29,12 +29,8 @@ jobs: arch: x64 cmake: 3.7 - - runs-on: windows-2016 - arch: x86 - cmake: 3.8 - - - runs-on: windows-2016 - arch: x86 + - runs-on: windows-2019 + arch: x64 # x86 compilers seem to be missing on 2019 image cmake: 3.18 name: 🐍 3.7 • CMake ${{ matrix.cmake }} • ${{ matrix.runs-on }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9ff2013ed..2bfd699a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -74,7 +74,6 @@ repos: rev: "v1.2.5" hooks: - id: pycln - additional_dependencies: [click<8.1] # Unpin when typer updates stages: [manual] # Checking for common mistakes @@ -127,7 +126,7 @@ repos: rev: "v0.942" hooks: - id: mypy - args: [--show-error-codes] + args: [] exclude: ^(tests|docs)/ additional_dependencies: [nox, rich] diff --git a/pyproject.toml b/pyproject.toml index f80cdc1f4..3ba1b4b22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,8 +24,10 @@ profile = "black" [tool.mypy] files = ["pybind11"] python_version = "3.6" -warn_unused_configs = true strict = true +show_error_codes = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true [[tool.mypy.overrides]] module = ["ghapi.*", "setuptools.*"] From ad0de0f5a6bebbebbeb7f8f2f15c0c1430f34268 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 11 Apr 2022 19:50:42 -0400 Subject: [PATCH 6/6] [pre-commit.ci] pre-commit autoupdate (#3863) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.1.0 → v4.2.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.1.0...v4.2.0) - [github.com/asottile/pyupgrade: v2.31.1 → v2.32.0](https://github.com/asottile/pyupgrade/compare/v2.31.1...v2.32.0) - [github.com/PyCQA/pylint: v2.13.4 → v2.13.5](https://github.com/PyCQA/pylint/compare/v2.13.4...v2.13.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2bfd699a6..9cfcef21f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ repos: # Standard hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.1.0" + rev: "v4.2.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -32,7 +32,7 @@ repos: # Upgrade old Python syntax - repo: https://github.com/asottile/pyupgrade - rev: "v2.31.1" + rev: "v2.32.0" hooks: - id: pyupgrade args: [--py36-plus] @@ -107,7 +107,7 @@ repos: # PyLint has native support - not always usable, but works for us - repo: https://github.com/PyCQA/pylint - rev: "v2.13.4" + rev: "v2.13.5" hooks: - id: pylint files: ^pybind11