From 554c0453776db915d09f679bd11201d8eb07e147 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 6 Jun 2022 12:15:45 -0400 Subject: [PATCH 1/3] 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 2/3] [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 3/3] 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``).