From 42a41bf3e70b5aa87945813f7bb722c2c75c14a8 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Fri, 3 Jun 2022 15:18:06 -0400 Subject: [PATCH 01/11] remove useless ctor (#3989) --- include/pybind11/functional.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index f2a752e9d..4034990d8 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -99,7 +99,7 @@ public: Return operator()(Args... args) const { gil_scoped_acquire acq; // casts the returned object as a rvalue to the return type - return object(hfunc.f(std::forward(args)...)).template cast(); + return hfunc.f(std::forward(args)...).template cast(); } }; From 554c0453776db915d09f679bd11201d8eb07e147 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 6 Jun 2022 12:15:45 -0400 Subject: [PATCH 02/11] enable two new clang-tidy checks (#3988) * enable two new clang-tidy checks * Use better loop var for char --- .clang-tidy | 4 ++++ tests/test_constants_and_functions.cpp | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e82443c4c..ddee835c1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ cppcoreguidelines-pro-type-static-cast-downcast, cppcoreguidelines-slicing, google-explicit-constructor, llvm-namespace-comment, +misc-definitions-in-headers, misc-misplaced-const, misc-non-copyable-objects, misc-static-assert, @@ -17,6 +18,7 @@ misc-throw-by-value-catch-by-reference, misc-uniqueptr-reset-release, misc-unused-parameters, modernize-avoid-bind, +modernize-loop-convert, modernize-make-shared, modernize-redundant-void-arg, modernize-replace-auto-ptr, @@ -63,6 +65,8 @@ readability-uniqueptr-delete-release, CheckOptions: - key: performance-for-range-copy.WarnOnAllAutoCopies value: true +- key: performance-inefficient-string-concatenation.StrictMode + value: true - key: performance-unnecessary-value-param.AllowedTypes value: 'exception_ptr$;' - key: readability-implicit-bool-conversion.AllowPointerConditions diff --git a/tests/test_constants_and_functions.cpp b/tests/test_constants_and_functions.cpp index 873fa1f55..1918a429c 100644 --- a/tests/test_constants_and_functions.cpp +++ b/tests/test_constants_and_functions.cpp @@ -31,8 +31,8 @@ py::bytes return_bytes() { std::string print_bytes(const py::bytes &bytes) { std::string ret = "bytes["; const auto value = static_cast(bytes); - for (size_t i = 0; i < value.length(); ++i) { - ret += std::to_string(static_cast(value[i])) + " "; + for (char c : value) { + ret += std::to_string(static_cast(c)) + ' '; } ret.back() = ']'; return ret; From c5fa3436c66ddc8e4a14b79e7c40f16182409d6e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 17:56:18 -0400 Subject: [PATCH 03/11] [pre-commit.ci] pre-commit autoupdate (#3951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v2.32.1 → v2.33.0](https://github.com/asottile/pyupgrade/compare/v2.32.1...v2.33.0) - [github.com/Lucas-C/pre-commit-hooks: v1.1.13 → v1.2.0](https://github.com/Lucas-C/pre-commit-hooks/compare/v1.1.13...v1.2.0) - [github.com/hadialqattan/pycln: v1.3.2 → v1.3.3](https://github.com/hadialqattan/pycln/compare/v1.3.2...v1.3.3) - [github.com/PyCQA/pylint: v2.13.8 → v2.14.1](https://github.com/PyCQA/pylint/compare/v2.13.8...v2.14.1) - [github.com/pre-commit/mirrors-mypy: v0.950 → v0.960](https://github.com/pre-commit/mirrors-mypy/compare/v0.950...v0.960) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03f829c25..e71944875 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,7 +32,7 @@ repos: # Upgrade old Python syntax - repo: https://github.com/asottile/pyupgrade - rev: "v2.32.1" + rev: "v2.33.0" hooks: - id: pyupgrade args: [--py36-plus] @@ -59,7 +59,7 @@ repos: # Changes tabs to spaces - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: "v1.1.13" + rev: "v1.2.0" hooks: - id: remove-tabs @@ -71,7 +71,7 @@ repos: # Autoremoves unused imports - repo: https://github.com/hadialqattan/pycln - rev: "v1.3.2" + rev: "v1.3.3" hooks: - id: pycln stages: [manual] @@ -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.8" + rev: "v2.14.1" hooks: - id: pylint files: ^pybind11 @@ -123,7 +123,7 @@ repos: # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v0.950" + rev: "v0.960" hooks: - id: mypy args: [] From 918892b97e21a4feca42cd5501c98c5b3aa8bb3f Mon Sep 17 00:00:00 2001 From: Maarten Baert Date: Tue, 7 Jun 2022 01:41:38 +0200 Subject: [PATCH 04/11] Make dtype::num() return type consistent with other functions (#3995) --- include/pybind11/numpy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index b8ba2259f..0c77a98dd 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -604,7 +604,7 @@ public: } /// type number of dtype. - ssize_t num() const { + int num() const { // Note: The signature, `dtype::num` follows the naming of NumPy's public // Python API (i.e., ``dtype.num``), rather than its internal // C API (``PyArray_Descr::type_num``). From e2dcd95407d5202019cecd2bb2827ee6a4a8f9f3 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 6 Jun 2022 22:33:28 -0400 Subject: [PATCH 05/11] chore: optimize dictionary access in strip_padding numpy (#3994) * emplace field descriptors * reserve sufficient capacity * remove std::move * properly iterate through dict * make handle casting more explicit * Revert to old dict api --- include/pybind11/numpy.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 0c77a98dd..43784f8e9 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -641,10 +641,14 @@ private: pybind11::str name; object format; pybind11::int_ offset; + field_descr(pybind11::str &&name, object &&format, pybind11::int_ &&offset) + : name{std::move(name)}, format{std::move(format)}, offset{std::move(offset)} {}; }; + auto field_dict = attr("fields").cast(); std::vector field_descriptors; + field_descriptors.reserve(field_dict.size()); - for (auto field : attr("fields").attr("items")()) { + for (auto field : field_dict.attr("items")()) { auto spec = field.cast(); auto name = spec[0].cast(); auto spec_fo = spec[1].cast(); @@ -653,8 +657,8 @@ private: if ((len(name) == 0u) && format.kind() == 'V') { continue; } - field_descriptors.push_back( - {(pybind11::str) name, format.strip_padding(format.itemsize()), offset}); + field_descriptors.emplace_back( + std::move(name), format.strip_padding(format.itemsize()), std::move(offset)); } std::sort(field_descriptors.begin(), From 0e956a2e4f7838fc26f42a6399bc358ae7248134 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Jun 2022 09:22:57 -0400 Subject: [PATCH 06/11] chore(deps): bump pre-commit/action from 2.0.3 to 3.0.0 (#3992) Bumps [pre-commit/action](https://github.com/pre-commit/action) from 2.0.3 to 3.0.0. - [Release notes](https://github.com/pre-commit/action/releases) - [Commits](https://github.com/pre-commit/action/compare/v2.0.3...v3.0.0) --- updated-dependencies: - dependency-name: pre-commit/action 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/format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 5eb228a70..70e3ddfa4 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -24,7 +24,7 @@ jobs: - 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 + - uses: pre-commit/action@v3.0.0 with: # Slow hooks are marked with manual - slow is okay here, run them too extra_args: --hook-stage manual --all-files From 21f0e72b0f29cc3b631b888447454b9a21642c22 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:02:25 -0400 Subject: [PATCH 07/11] [pre-commit.ci] pre-commit autoupdate (#4003) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e71944875..3b4c90656 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.2.0" + rev: "v4.3.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.33.0" + rev: "v2.34.0" hooks: - id: pyupgrade args: [--py36-plus] @@ -123,7 +123,7 @@ repos: # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v0.960" + rev: "v0.961" hooks: - id: mypy args: [] @@ -164,7 +164,7 @@ repos: # Clang format the codebase automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v14.0.3" + rev: "v14.0.4-1" hooks: - id: clang-format types_or: [c++, c, cuda] From 0964a9093a728dbf67b9b98c6371752b1a346f25 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Tue, 14 Jun 2022 14:20:26 -0400 Subject: [PATCH 08/11] Add a missing std::move in numpy.h (#4005) --- include/pybind11/numpy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 43784f8e9..0291b02d0 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -1409,7 +1409,7 @@ PYBIND11_NOINLINE void register_structured_dtype(any_container } auto tindex = std::type_index(tinfo); - numpy_internals.registered_dtypes[tindex] = {dtype_ptr, format_str}; + numpy_internals.registered_dtypes[tindex] = {dtype_ptr, std::move(format_str)}; get_internals().direct_conversions[tindex].push_back(direct_converter); } From 2ad974c9455c2ed46c3704df11852cf0a5462b22 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 14:36:49 -0400 Subject: [PATCH 09/11] [pre-commit.ci] pre-commit autoupdate (#4021) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/PyCQA/pylint: v2.14.1 → v2.14.3](https://github.com/PyCQA/pylint/compare/v2.14.1...v2.14.3) - [github.com/pre-commit/mirrors-clang-format: v14.0.4-1 → v14.0.5](https://github.com/pre-commit/mirrors-clang-format/compare/v14.0.4-1...v14.0.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b4c90656..fc91dfe54 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -107,7 +107,7 @@ repos: # PyLint has native support - not always usable, but works for us - repo: https://github.com/PyCQA/pylint - rev: "v2.14.1" + rev: "v2.14.3" hooks: - id: pylint files: ^pybind11 @@ -164,7 +164,7 @@ repos: # Clang format the codebase automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v14.0.4-1" + rev: "v14.0.5" hooks: - id: clang-format types_or: [c++, c, cuda] From c3e9173f0f6da05a8463db093c4bc85934872c84 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 21 Jun 2022 14:55:49 -0400 Subject: [PATCH 10/11] ci: use almalinux instead of centos, add 9 (#4020) Signed-off-by: Henry Schreiner --- .github/workflows/ci.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b537e6e1..cb7966839 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -584,19 +584,25 @@ jobs: strategy: fail-fast: false matrix: - centos: - - centos7 # GCC 4.8 - - stream8 + container: + - "centos:7" # GCC 4.8 + - "almalinux:8" + - "almalinux:9" - name: "🐍 3 • CentOS ${{ matrix.centos }} • x64" - container: "quay.io/centos/centos:${{ matrix.centos }}" + name: "🐍 3 • ${{ matrix.container }} • x64" + container: "${{ matrix.container }}" steps: - uses: actions/checkout@v3 - - name: Add Python 3 + - name: Add Python 3 (RHEL 7) + if: matrix.container == 'centos:7' run: yum update -y && yum install -y python3-devel gcc-c++ make git + - name: Add Python 3 (RHEL 8+) + if: matrix.container != 'centos:7' + run: dnf update -y && dnf install -y python3-devel gcc-c++ make git + - name: Update pip run: python3 -m pip install --upgrade pip From dd3bf7fd128177b9bf17b397cff64f56190a567b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jun 2022 19:39:19 -0400 Subject: [PATCH 11/11] [pre-commit.ci] pre-commit autoupdate (#4030) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/hadialqattan/pycln: v1.3.3 → v1.3.5](https://github.com/hadialqattan/pycln/compare/v1.3.3...v1.3.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc91dfe54..e4880830f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -71,7 +71,7 @@ repos: # Autoremoves unused imports - repo: https://github.com/hadialqattan/pycln - rev: "v1.3.3" + rev: "v1.3.5" hooks: - id: pycln stages: [manual]