Fix py::cast from pytype rvalue to pytype (#3949)

* Fix py::cast from pytype rvalue to pytype

Previously, py::cast blindly assumed that the destination type was a C++
type rather than a python type when the source type was an rvalue.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Maarten Baert
2022-05-16 22:51:01 +02:00
committed by GitHub
parent 48c7be4a56
commit 72eea20afd
3 changed files with 24 additions and 3 deletions

View File

@@ -289,4 +289,7 @@ TEST_SUBMODULE(copy_move_policies, m) {
py::return_value_policy::move);
m.def(
"get_moveissue2", [](int i) { return MoveIssue2(i); }, py::return_value_policy::move);
// Make sure that cast from pytype rvalue to other pytype works
m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast<py::int_>(); });
}