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

Bool not cast to int when using union passthrough strategy #623

Open
danielnelson opened this issue Jan 30, 2025 · 0 comments
Open

Bool not cast to int when using union passthrough strategy #623

danielnelson opened this issue Jan 30, 2025 · 0 comments

Comments

@danielnelson
Copy link

When structuring a bool as an int, the behavior is to convert it to an int:

converter = cattrs.Converter()
result = converter.structure(True, int)
assert type(result) is int
assert result == 1

But when using configure_union_passthrough structuring to a union, it doesn't get converted and remains a bool:

converter = cattrs.Converter()
cattrs.strategies.configure_union_passthrough(Union[int, bool, float, str, None], converter)
result = converter.structure(True, Union[int, float])
assert type(result) is bool
assert result

My expectation was that it would be converted to an int in both cases.

This is with cattrs 24.1.2.

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

No branches or pull requests

1 participant