Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,9 @@ class str : public object {
# endif

#endif
// Avoid ambiguity when converting from kwargs (GCC)
template <typename T, detail::enable_if_t<std::is_same<T, kwargs>::value, int> = 0>
explicit str(const T &k) : str(static_cast<handle>(k)) {}

explicit str(const bytes &b);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the handle ctor below call release instead of ptr for safety?


Expand Down
4 changes: 4 additions & 0 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,3 +1212,7 @@ TEST_SUBMODULE(pytypes, m) {
return py::isinstance<RealNumber>(x);
});
}

TEST_SUBMODULE(pytypes, kwargs_str) {
m.def("kwargs_to_str", [](py::kwargs kwargs) { return py::str(kwargs); });
}
Loading