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/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5de4a2c6..57dd7e066 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -585,19 +585,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 diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 9ab75c186..2bd50877c 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -25,7 +25,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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c7e35649..86f71def8 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 @@ -33,7 +33,7 @@ repos: # Upgrade old Python syntax - repo: https://github.com/asottile/pyupgrade - rev: "v2.32.1" + rev: "v2.34.0" hooks: - id: pyupgrade args: [--py36-plus] @@ -60,7 +60,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 exclude: (^docs/.*|\.patch)?$ @@ -73,7 +73,7 @@ repos: # Autoremoves unused imports - repo: https://github.com/hadialqattan/pycln - rev: "v1.3.2" + rev: "v1.3.5" hooks: - id: pycln stages: [manual] @@ -110,7 +110,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.3" hooks: - id: pylint files: ^pybind11 @@ -126,7 +126,7 @@ repos: # Check static types with mypy - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v0.950" + rev: "v0.961" hooks: - id: mypy args: [] @@ -167,7 +167,7 @@ repos: # Clang format the codebase automatically - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v14.0.3" + rev: "v14.0.5" hooks: - id: clang-format types_or: [c++, c, cuda] 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(); } }; diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index b8ba2259f..0291b02d0 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``). @@ -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(), @@ -1405,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); } 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;