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

docs: add docs about Union types and casting #383

Merged
merged 7 commits into from
Dec 17, 2022
Merged

Conversation

andrewthetechie
Copy link
Owner

Copy link

@david-wahlstedt david-wahlstedt left a comment

Choose a reason for hiding this comment

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

Looks good to me! I approve, but if you want you can adjust the comment according (kind of) to my suggestion.

*******************************************

When using Union types, pydantic will cast the value to the first type in the Union. This can cause unintended type casting. For example, if you have a field
of type Union[float, int], and you set the value to 1, pydantic will cast the value to a float 1.0. This is an issue with Pydantic. More info can be found in

Choose a reason for hiding this comment

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

Maybe also worth noting here, that in the other direction, for x: Union[int, float], having x=1.99 in the constructor , not only the type gets cast into int, but the value actually changes to 1 (as a necessary consequence).

Choose a reason for hiding this comment

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

@andrewthetechie : I'm not used to reviewing in github, but I saw that in commit 70b9bd2 , the actual tests are added. But this didn't appear in the review pane above. When I click the "Add your review" in the link below this message, I get the same view as that I already approved.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for the example, I added that as well.

The tests don't show up in the review pane because I added them in another branch without a PR.

@andrewthetechie
Copy link
Owner Author

@all-contributors add @david-wahlstedt for doc, review

@allcontributors
Copy link

@andrewthetechie

I've put up a pull request to add @david-wahlstedt! 🎉

@andrewthetechie andrewthetechie merged commit 2af6167 into main Dec 17, 2022
@andrewthetechie andrewthetechie deleted the dunion-types-docs branch December 17, 2022 18:29
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