mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-02 20:51:36 +00:00
* Fix #3812 and fix const of inplace assignments * Fix missing tests * Revert operator overloading changes * calculate answer first for tests * Simplify tests * Add more tests * Add a couple more tests * Add test_inplace_lshift, test_inplace_rshift for completeness. * Update tests * Shortcircuit on self assigment and address reviewer comment * broaden skip for self assignment * One more reviewer comment * Document opt behavior and make consistent * Revert unnecessary change * Clarify comment Co-authored-by: Ralf W. Grosse-Kunstleve <rwgk@google.com>
This commit is contained in:
@@ -756,4 +756,38 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
}
|
||||
return o;
|
||||
});
|
||||
|
||||
// testing immutable object augmented assignment: #issue 3812
|
||||
m.def("inplace_append", [](py::object &a, const py::object &b) {
|
||||
a += b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_subtract", [](py::object &a, const py::object &b) {
|
||||
a -= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_multiply", [](py::object &a, const py::object &b) {
|
||||
a *= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_divide", [](py::object &a, const py::object &b) {
|
||||
a /= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_or", [](py::object &a, const py::object &b) {
|
||||
a |= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_and", [](py::object &a, const py::object &b) {
|
||||
a &= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_lshift", [](py::object &a, const py::object &b) {
|
||||
a <<= b;
|
||||
return a;
|
||||
});
|
||||
m.def("inplace_rshift", [](py::object &a, const py::object &b) {
|
||||
a >>= b;
|
||||
return a;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user