Skip to content

Commit

Permalink
py: Fix __contains__ not converting to map key type since pybind11 2.8.0
Browse files Browse the repository at this point in the history
Fixes a pybind11 API breaking change that was uncovered by issue #25
  • Loading branch information
leoetlino committed Dec 26, 2022
1 parent 2d77e4e commit ba5f630
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions py/pybind11_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ py::class_<Map, holder_type> BindMap(py::handle scope, const std::string& name,
}),
"dictionary"_a)
.def(py::self == py::self)
.def(
"__contains__",
[](const Map& map, const py::object& arg) {
try {
auto key = py::cast<Key>(arg);
return map.find(key) != map.end();
} catch (const py::cast_error&) {
return false;
}
},
py::prepend{})
.def("clear", &Map::clear)
.def(
"get",
Expand Down

0 comments on commit ba5f630

Please sign in to comment.