Skip to content

Commit 7f49381

Browse files
committed
Fix ambiguous py::str(kwargs) overload on GCC
1 parent 799f591 commit 7f49381

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/pybind11/pytypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,11 @@ class str : public object {
16401640
str(std::u8string_view s) : str(reinterpret_cast<const char *>(s.data()), s.size()) {}
16411641
# endif
16421642

1643+
// Avoid ambiguity when converting from kwargs (GCC)
1644+
explicit str(const kwargs &k)
1645+
: str(static_cast<handle>(k)) {}
1646+
1647+
16431648
#endif
16441649

16451650
explicit str(const bytes &b);

tests/test_pytypes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,3 +1212,10 @@ TEST_SUBMODULE(pytypes, m) {
12121212
return py::isinstance<RealNumber>(x);
12131213
});
12141214
}
1215+
1216+
1217+
TEST_SUBMODULE(pytypes, kwargs_str) {
1218+
m.def("kwargs_to_str", [](py::kwargs kwargs) {
1219+
return py::str(kwargs);
1220+
});
1221+
}

0 commit comments

Comments
 (0)