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:
Aaron Gokaslan
2022-10-17 19:15:08 -04:00
committed by GitHub
parent 5b5547bc1b
commit b926396bdf
3 changed files with 39 additions and 3 deletions

View File

@@ -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));