File tree 1 file changed +14
-6
lines changed 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -694,13 +694,9 @@ struct ItemsViewImpl : public detail::items_view {
694
694
Map ↦
695
695
};
696
696
697
- template <typename KeyType>
698
- str format_message_key_error (const KeyType &key) {
697
+ inline str format_message_key_error_key_object (handle py_key) {
699
698
str message = " pybind11::bind_map key" ;
700
- object py_key;
701
- try {
702
- py_key = cast (key);
703
- } catch (const std::exception &) {
699
+ if (!py_key) {
704
700
return message;
705
701
}
706
702
try {
@@ -720,6 +716,18 @@ str format_message_key_error(const KeyType &key) {
720
716
return message;
721
717
}
722
718
719
+ template <typename KeyType>
720
+ str format_message_key_error (const KeyType &key) {
721
+ object py_key;
722
+ try {
723
+ py_key = cast (key);
724
+ } catch (const std::exception &) {
725
+ do { // Trick to avoid "empty catch" warning/error.
726
+ } while (false );
727
+ }
728
+ return format_message_key_error_key_object (py_key);
729
+ }
730
+
723
731
PYBIND11_NAMESPACE_END (detail)
724
732
725
733
template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
You can’t perform that action at this time.
0 commit comments