Skip to content

Commit

Permalink
Print key in map.getitem/delitem KeyError
Browse files Browse the repository at this point in the history
  • Loading branch information
sarlinpe committed Oct 6, 2024
1 parent 7e418f4 commit 71e8a37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/stl_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&
[](Map &m, const KeyType &k) -> MappedType & {
auto it = m.find(k);
if (it == m.end()) {
throw key_error();
throw key_error(str(cast(k)).cast<std::string>());
}
return it->second;
},
Expand All @@ -808,7 +808,7 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&
cl.def("__delitem__", [](Map &m, const KeyType &k) {
auto it = m.find(k);
if (it == m.end()) {
throw key_error();
throw key_error(str(cast(k)).cast<std::string>());
}
m.erase(it);
});
Expand Down

0 comments on commit 71e8a37

Please sign in to comment.