Skip to content

Commit 53f661e

Browse files
Xiaofei Wangcopybara-github
authored andcommitted
Internal Change.
PiperOrigin-RevId: 532970607
1 parent a8fed75 commit 53f661e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pybind11_abseil/statusor_caster.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ struct type_caster<absl::StatusOr<PayloadType>> {
4242
using PayloadCaster = make_caster<PayloadType>;
4343
using StatusCaster = make_caster<absl::Status>;
4444

45+
#if defined(PYBIND11_HAS_RETURN_VALUE_POLICY_PACK)
46+
using return_value_policy_t = const return_value_policy_pack&;
47+
PYBIND11_TYPE_CASTER_RVPP(absl::StatusOr<PayloadType>, PayloadCaster::name);
48+
#else
49+
using return_value_policy_t = return_value_policy;
4550
PYBIND11_TYPE_CASTER(absl::StatusOr<PayloadType>, PayloadCaster::name);
51+
#endif
4652

4753
bool load(handle src, bool convert) {
4854
PayloadCaster payload_caster;
@@ -70,27 +76,27 @@ struct type_caster<absl::StatusOr<PayloadType>> {
7076

7177
// Convert C++ -> Python.
7278
static handle cast(const absl::StatusOr<PayloadType>* src,
73-
return_value_policy policy, handle parent,
79+
return_value_policy_t policy, handle parent,
7480
bool throw_exception = true) {
7581
if (!src) return none().release();
7682
return cast_impl(*src, policy, parent, throw_exception);
7783
}
7884

7985
static handle cast(const absl::StatusOr<PayloadType>& src,
80-
return_value_policy policy, handle parent,
86+
return_value_policy_t policy, handle parent,
8187
bool throw_exception = true) {
8288
return cast_impl(src, policy, parent, throw_exception);
8389
}
8490

8591
static handle cast(absl::StatusOr<PayloadType>&& src,
86-
return_value_policy policy, handle parent,
92+
return_value_policy_t policy, handle parent,
8793
bool throw_exception = true) {
8894
return cast_impl(std::move(src), policy, parent, throw_exception);
8995
}
9096

9197
private:
9298
template <typename CType>
93-
static handle cast_impl(CType&& src, return_value_policy policy,
99+
static handle cast_impl(CType&& src, return_value_policy_t policy,
94100
handle parent, bool throw_exception) {
95101
google::internal::CheckStatusModuleImported();
96102
if (src.ok()) {

0 commit comments

Comments
 (0)