Merge branch 'master' into smart_holder

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-06-27 22:24:23 -07:00
commit cad2609381
7 changed files with 36 additions and 22 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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>(args)...)).template cast<Return>();
return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
}
};

View File

@ -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<dict>();
std::vector<field_descr> 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<tuple>();
auto name = spec[0].cast<pybind11::str>();
auto spec_fo = spec[1].cast<tuple>();
@ -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<field_descriptor>
}
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);
}

View File

@ -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<std::string>(bytes);
for (size_t i = 0; i < value.length(); ++i) {
ret += std::to_string(static_cast<int>(value[i])) + " ";
for (char c : value) {
ret += std::to_string(static_cast<int>(c)) + ' ';
}
ret.back() = ']';
return ret;