File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 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 {
694694 Map ↦
695695};
696696
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) {
699698 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) {
704700 return message;
705701 }
706702 try {
@@ -720,6 +716,18 @@ str format_message_key_error(const KeyType &key) {
720716 return message;
721717}
722718
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+
723731PYBIND11_NAMESPACE_END (detail)
724732
725733template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
You can’t perform that action at this time.
0 commit comments