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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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.
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.

1 participant