✨ Use Pydantic for parameter validation#1831
Draft
svlandeg wants to merge 27 commits into
Draft
Conversation
svlandeg
commented
Jun 10, 2026
| ("No", False), | ||
| ], | ||
| ) | ||
| def test_bool_convert_valid(cli_value: str, expected: bool) -> None: |
Member
Author
There was a problem hiding this comment.
This test currently mimics master behaviour 100%.
Contributor
📝 Docs previewLast commit b6165b7 at: https://695fb8cd.typertiangolo.pages.dev |
…o feat/pydantic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP: please don't comment/review yet, this will still change a lot.
Description
Make Pydantic a required dependency and rely on it for parameter validation.
adapters.pyparam_types.pyExtended functionality
[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]Breaking changes
click_typeand open bounds throughmin_openandmax_open. This greatly simplifies the code base while still providing an alternative by settingparserinstead.%Y-%m-%dinstead of[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]) even though all three (and more) will work. It's not just those three anymore, so it felt arbitrary to show 3 out ofn. We can decide to reverse the change and keep showing those three formats though.TyperPathandTyperChoicewere moved into the new moduleparam_types.pyBug fixes
def main(age: int = typer.Option(15.3))will now throw a validation error by Pydantic instead ofint(15.3)converting it to15. I consider this a bug fix instead of a regression, and have added a testtest_int_rejects_float_defaultfor it.loc: str = typer.Option(..., resolve_path=True)is now parsed as aTyperPathinstead of as aSTRINGonmaster.Decision points
_parse_cli_boolwas created to ensure we still parse""asFalseand to strip whitespace from something like" True ". This is just to mimic old Click behaviour. If we don't do this preprocessing (cleaner code base), the empty string and the non-stripped strings won't pass Pydantic validation and it would be slightly breaking.AI Disclaimer
Cursor was used as a micro-managed junior. Every single edit was reviewed & understood by me.
Checklist