Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform two passes in the variant caster #769

Merged
merged 1 commit into from
Nov 4, 2024
Merged

Conversation

tjstum
Copy link
Contributor

@tjstum tjstum commented Oct 24, 2024

When converting a Python object that wraps a T to a std::variant<U,T>, where U is implicitly convertible from T, the variant caster will cast to the U (even though the Python object is definitely a T)

The included test case demonstrates the issue. pybind11 does two pass conversion in this case. One can work around the issue by using noconvert() on the argument. But it seems that it would be a friendlier default to make type conversions in a variant work as expected.

@wjakob
Copy link
Owner

wjakob commented Nov 3, 2024

LGTM, thanks! Can you rebase/resolve the merge conflict?

When converting a Python object that wraps a `T` to a
`std::variant<U,T>`, where `U` is implicitly convertible
from `T`, the variant caster will cast to the `U` (even though the
Python object is definitely a `T`)

The included test case demonstrates the issue. pybind11 does two pass
conversion in this case. One can work around the issue by using
`noconvert()` on the argument. But it seems that it would be a
friendlier default to make type conversions in a variant work as
expected.
@tjstum
Copy link
Contributor Author

tjstum commented Nov 3, 2024

Just done, thanks!

@wjakob wjakob merged commit 3528abf into wjakob:master Nov 4, 2024
31 checks passed
@wjakob
Copy link
Owner

wjakob commented Nov 4, 2024

Thanks!

@tjstum tjstum deleted the variant branch November 4, 2024 17:51
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.

2 participants