mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
bugfix: py contains raises errors when appropiate (#4209)
* bugfix: contains now throws an exception if the key is not hashable * Fix tests and improve robustness * Remove todo * Workaround PyPy corner case * PyPy xfail * Fix typo * fix xfail * Make clang-tidy happy * Remove redundant exc checking
This commit is contained in:
@@ -183,7 +183,7 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
return d2;
|
||||
});
|
||||
m.def("dict_contains",
|
||||
[](const py::dict &dict, py::object val) { return dict.contains(val); });
|
||||
[](const py::dict &dict, const py::object &val) { return dict.contains(val); });
|
||||
m.def("dict_contains",
|
||||
[](const py::dict &dict, const char *val) { return dict.contains(val); });
|
||||
|
||||
@@ -538,6 +538,9 @@ TEST_SUBMODULE(pytypes, m) {
|
||||
|
||||
m.def("hash_function", [](py::object obj) { return py::hash(std::move(obj)); });
|
||||
|
||||
m.def("obj_contains",
|
||||
[](py::object &obj, const py::object &key) { return obj.contains(key); });
|
||||
|
||||
m.def("test_number_protocol", [](const py::object &a, const py::object &b) {
|
||||
py::list l;
|
||||
l.append(a.equal(b));
|
||||
|
||||
Reference in New Issue
Block a user