Skip to content

[smart_holder] git merge master #3813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 18, 2022
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ jobs:


# This verifies that the documentation is not horribly broken, and does a
# basic sanity check on the SDist.
# basic validation check on the SDist.
doxygen:
name: "Documentation build test"
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_sh_def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ jobs:


# This verifies that the documentation is not horribly broken, and does a
# basic sanity check on the SDist.
# basic validation check on the SDist.
doxygen:
name: "Documentation build test"
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_sh_def.yml.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- ci.yml 2022-03-10 10:32:48.282365464 -0800
+++ ci_sh_def.yml 2022-03-10 10:38:55.058650883 -0800
--- ci.yml 2022-03-18 00:17:40.217744123 -0700
+++ ci_sh_def.yml 2022-03-18 00:19:11.625791651 -0700
@@ -1,4 +1,16 @@
-name: CI
+# PLEASE KEEP THIS GROUP OF FILES IN SYNC AT ALL TIMES:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:

# Upgrade old Python syntax
- repo: https://github.com/asottile/pyupgrade
rev: "v2.31.0"
rev: "v2.31.1"
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand Down Expand Up @@ -66,14 +66,14 @@ repos:
exclude: (^docs/.*|\.patch)?$

- repo: https://github.com/sirosen/texthooks
rev: "0.2.2"
rev: "0.3.1"
hooks:
- id: fix-ligatures
- id: fix-smartquotes

# Autoremoves unused imports
- repo: https://github.com/hadialqattan/pycln
rev: "v1.2.4"
rev: "v1.2.5"
hooks:
- id: pycln

Expand Down Expand Up @@ -125,7 +125,7 @@ repos:

# Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.931"
rev: "v0.940"
hooks:
- id: mypy
args: [--show-error-codes]
Expand All @@ -134,7 +134,7 @@ repos:

# Checks the manifest for missing files (native support)
- repo: https://github.com/mgedmin/check-manifest
rev: "0.47"
rev: "0.48"
hooks:
- id: check-manifest
# This is a slow hook, so only run this if --hook-stage manual is passed
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/pycpp/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ buffer objects (e.g. a NumPy matrix).
/* Request a buffer descriptor from Python */
py::buffer_info info = b.request();

/* Some sanity checks ... */
/* Some basic validation checks ... */
if (info.format != py::format_descriptor<Scalar>::format())
throw std::runtime_error("Incompatible format: expected a double array!");

Expand Down
5 changes: 4 additions & 1 deletion docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,10 @@ You can use these targets to build complex applications. For example, the
target_link_libraries(example PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)

pybind11_extension(example)
pybind11_strip(example)
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
# Strip unnecessary sections of the binary on Linux/macOS
pybind11_strip(example)
endif()

set_target_properties(example PROPERTIES CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden")
Expand Down
4 changes: 2 additions & 2 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1038,12 +1038,12 @@ public:
Name(const object &o) \
: Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw error_already_set(); \
throw ::pybind11::error_already_set(); \
} \
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
if (!m_ptr) \
throw error_already_set(); \
throw ::pybind11::error_already_set(); \
}

#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun) \
Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ struct variant_caster<V<Ts...>> {
bool load_alternative(handle src, bool convert, type_list<U, Us...>) {
auto caster = make_caster<U>();
if (caster.load(src, convert)) {
value = cast_op<U>(caster);
value = cast_op<U>(std::move(caster));
return true;
}
return load_alternative(src, convert, type_list<Us...>{});
Expand Down
33 changes: 33 additions & 0 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@

#include <utility>

namespace external {
namespace detail {
bool check(PyObject *o) { return PyFloat_Check(o) != 0; }

PyObject *conv(PyObject *o) {
PyObject *ret = nullptr;
if (PyLong_Check(o)) {
double v = PyLong_AsDouble(o);
if (!(v == -1.0 && PyErr_Occurred())) {
ret = PyFloat_FromDouble(v);
}
} else {
PyErr_SetString(PyExc_TypeError, "Unexpected type");
}
return ret;
}

PyObject *default_constructed() { return PyFloat_FromDouble(0.0); }
} // namespace detail
class float_ : public py::object {
PYBIND11_OBJECT_CVT(float_, py::object, external::detail::check, external::detail::conv)

float_() : py::object(external::detail::default_constructed(), stolen_t{}) {}

double get_value() const { return PyFloat_AsDouble(this->ptr()); }
};
} // namespace external

TEST_SUBMODULE(pytypes, m) {
// test_bool
m.def("get_bool", [] { return py::bool_(false); });
Expand Down Expand Up @@ -545,4 +573,9 @@ TEST_SUBMODULE(pytypes, m) {
py::detail::accessor_policies::tuple_item::set(o, (py::size_t) 0, s0);
return o;
});

m.def("square_float_", [](const external::float_ &x) -> double {
double v = x.get_value();
return v * v;
});
}
5 changes: 5 additions & 0 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,8 @@ def test_implementation_details():
assert m.tuple_item_set_ssize_t() == ("emely", "edmond")
assert m.tuple_item_get_size_t(tup) == 93
assert m.tuple_item_set_size_t() == ("candy", "cat")


def test_external_float_():
r1 = m.square_float_(2.0)
assert r1 == 4.0