Skip to content

Conversation

@Mohataseem89
Copy link

Fixes #5938

GCC reports an ambiguous overload when calling py::str(kwargs) due to
multiple implicit conversions (handle/object)

this PR adds an explicit str(const kwargs&) constructor forwarding to
str(handle), resolving the ambiguity while preserving existing behavior

a small regression test is added to ensure py::str(kwargs) remains
unambiguous across compilers


#endif

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?

# endif

// Avoid ambiguity when converting from kwargs (GCC)
explicit str(const kwargs &k) : str(static_cast<handle>(k)) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yuck, it's weird because the handle goes through the raw_str function and steals THAT REFERENCE.

@Mohataseem89
Copy link
Author

The intent here was to strictly mirror the existing str(handle) behavior
the new str(const kwargs) constructor only disambiguates overload resolution and forwards directly to the handle-based path without changing ownership semantics

@Mohataseem89
Copy link
Author

raw_str() expects a borrowed reference and creates a new string object, so passing ptr() is consistent with how str(handle) already behaves elsewhere in the codebase.
using release() here would transfer ownership and could be unsafe, since kwargs itself does not create a new reference

@rwgk
Copy link
Collaborator

rwgk commented Dec 29, 2025

Usually we do reviews only after all (or at least most) tests work. Currently basically everything is failing.

@Mohataseem89
Copy link
Author

thanks for the clarification agreed.

I will take a closer look at the CI failures and update the PR accordingly before requesting further review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: call of overloaded ‘str(const pybind11::kwargs&)’ is ambiguous

3 participants