Skip to content

Commit 87e315a

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 9d4b4df + 8b1944d commit 87e315a

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ jobs:
668668

669669

670670
# This verifies that the documentation is not horribly broken, and does a
671-
# basic sanity check on the SDist.
671+
# basic validation check on the SDist.
672672
doxygen:
673673
name: "Documentation build test"
674674
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ repos:
3333

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

6868
- repo: https://github.com/sirosen/texthooks
69-
rev: "0.2.2"
69+
rev: "0.3.1"
7070
hooks:
7171
- id: fix-ligatures
7272
- id: fix-smartquotes
7373

7474
# Autoremoves unused imports
7575
- repo: https://github.com/hadialqattan/pycln
76-
rev: "v1.2.4"
76+
rev: "v1.2.5"
7777
hooks:
7878
- id: pycln
7979

@@ -125,7 +125,7 @@ repos:
125125

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

135135
# Checks the manifest for missing files (native support)
136136
- repo: https://github.com/mgedmin/check-manifest
137-
rev: "0.47"
137+
rev: "0.48"
138138
hooks:
139139
- id: check-manifest
140140
# This is a slow hook, so only run this if --hook-stage manual is passed

docs/advanced/pycpp/numpy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ buffer objects (e.g. a NumPy matrix).
8787
/* Request a buffer descriptor from Python */
8888
py::buffer_info info = b.request();
8989
90-
/* Some sanity checks ... */
90+
/* Some basic validation checks ... */
9191
if (info.format != py::format_descriptor<Scalar>::format())
9292
throw std::runtime_error("Incompatible format: expected a double array!");
9393

docs/compiling.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,10 @@ You can use these targets to build complex applications. For example, the
505505
target_link_libraries(example PRIVATE pybind11::module pybind11::lto pybind11::windows_extras)
506506
507507
pybind11_extension(example)
508-
pybind11_strip(example)
508+
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
509+
# Strip unnecessary sections of the binary on Linux/macOS
510+
pybind11_strip(example)
511+
endif()
509512
510513
set_target_properties(example PROPERTIES CXX_VISIBILITY_PRESET "hidden"
511514
CUDA_VISIBILITY_PRESET "hidden")

include/pybind11/pytypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,12 @@ public:
10381038
Name(const object &o) \
10391039
: Parent(check_(o) ? o.inc_ref().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
10401040
if (!m_ptr) \
1041-
throw error_already_set(); \
1041+
throw ::pybind11::error_already_set(); \
10421042
} \
10431043
/* NOLINTNEXTLINE(google-explicit-constructor) */ \
10441044
Name(object &&o) : Parent(check_(o) ? o.release().ptr() : ConvertFun(o.ptr()), stolen_t{}) { \
10451045
if (!m_ptr) \
1046-
throw error_already_set(); \
1046+
throw ::pybind11::error_already_set(); \
10471047
}
10481048

10491049
#define PYBIND11_OBJECT_CVT_DEFAULT(Name, Parent, CheckFun, ConvertFun) \

tests/test_pytypes.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@
1111

1212
#include <utility>
1313

14+
namespace external {
15+
namespace detail {
16+
bool check(PyObject *o) { return PyFloat_Check(o) != 0; }
17+
18+
PyObject *conv(PyObject *o) {
19+
PyObject *ret = nullptr;
20+
if (PyLong_Check(o)) {
21+
double v = PyLong_AsDouble(o);
22+
if (!(v == -1.0 && PyErr_Occurred())) {
23+
ret = PyFloat_FromDouble(v);
24+
}
25+
} else {
26+
PyErr_SetString(PyExc_TypeError, "Unexpected type");
27+
}
28+
return ret;
29+
}
30+
31+
PyObject *default_constructed() { return PyFloat_FromDouble(0.0); }
32+
} // namespace detail
33+
class float_ : public py::object {
34+
PYBIND11_OBJECT_CVT(float_, py::object, external::detail::check, external::detail::conv)
35+
36+
float_() : py::object(external::detail::default_constructed(), stolen_t{}) {}
37+
38+
double get_value() const { return PyFloat_AsDouble(this->ptr()); }
39+
};
40+
} // namespace external
41+
1442
TEST_SUBMODULE(pytypes, m) {
1543
// test_bool
1644
m.def("get_bool", [] { return py::bool_(false); });
@@ -545,4 +573,9 @@ TEST_SUBMODULE(pytypes, m) {
545573
py::detail::accessor_policies::tuple_item::set(o, (py::size_t) 0, s0);
546574
return o;
547575
});
576+
577+
m.def("square_float_", [](const external::float_ &x) -> double {
578+
double v = x.get_value();
579+
return v * v;
580+
});
548581
}

tests/test_pytypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,3 +634,8 @@ def test_implementation_details():
634634
assert m.tuple_item_set_ssize_t() == ("emely", "edmond")
635635
assert m.tuple_item_get_size_t(tup) == 93
636636
assert m.tuple_item_set_size_t() == ("candy", "cat")
637+
638+
639+
def test_external_float_():
640+
r1 = m.square_float_(2.0)
641+
assert r1 == 4.0

0 commit comments

Comments
 (0)