Repository navigation
✨ Use Pydantic for parameter validation - #1831
Conversation
| ("No", False), | ||
| ], | ||
| ) | ||
| def test_bool_convert_valid(cli_value: str, expected: bool) -> None: |
There was a problem hiding this comment.
This test currently mimics master behaviour 100%.
…o feat/pydantic
|
I updated this branch with And then:
Modules renamed:
New symbols in existing modules:
|
This comment was marked as resolved.
This comment was marked as resolved.
|
On pydantic's startup time, I'd also suggest setting |
# Conflicts: # typer/_click/core.py # typer/main.py
Thanks for the note @Viicos! 🙏 I've created a context manager If I understand correctly, this env var works since Pydantic 2.7.0 and our lower pin in 2.5.3. That means that for older Pydantic versions, this is a no-op. I think that's fine and no reason to raise the floor. |
tiangolo
left a comment
There was a problem hiding this comment.
Amazing, I'm so excited about this! 🚀 🤩
|
I'm sorry but this change should have triggered a 1.0 release. It should not have been a 0.x release. First I want to say, I love Pydantic and am glad to see it being used for this type of purpose. However, this change (in particular the removal of the vendored Overall I have been extremely disappointed with the breaking changes to Typer that have occurred over the last year. First there was the vendoring of Yes, I know Typer is still ZeroVer and still claims to be in "beta" status, but it must have hundreds of thousands of users now -- you cannot seriously tell me that it's appropriate to break a significant fraction of those users' code with no advance warning whenever you feel like it. At this point I am forced to conclude that Typer is still a "sandbox" project and simply not appropriate for any sort of serious work, because breaking changes just happen all the time with no advance warning (without even being listed in the changelog!). Since the previous breakage I have already been migrating all my apps to |
…rrors, handle similar failures consistently (#750) * raise BagelValidationError instead of logging + exiting in phenotypic input validations * log independent pheno input validation errors together and refactor age transform error raising * raise BagelFileError instead of calling log_error for input file parsing errors * handle logging and exiting for phenotypic file parsing errors * raise BagelValidationError and BagelResourceError in BIDS steps * handle error with vocab fetching in main command * refactor BIDS validations * create PipelineCatalog class to allow lazy-loading of remote catalog on first access * handle subjects missing from phenotypic data in main command logic * remove leftover utility for checking pipeline catalog availability * standardize handling of resource fetching * rename validate_dataset_description to convey that it returns a validated object * raise BagelValidationError instead of logging + exiting for pipeline-version validation * update assertions and mocks for requested resources in integration tests * update error assertions in tests * test pheno file parsing errors returned together * test app exits when BIDS vocab fetching fails * test harmonize-pheno errors gracefully for age transformation failure * add placeholder dataset description to test of input file parsing errors * separate logging and exiting globally * catch age transformation error more precisely * temporarily pin typer to avoid removed support for click_type from 0.29.0 - fastapi/typer#1831 * test bids2tsv exits gracefully for failed BIDS vocab fetching * test informative error when BIDS subjects don't match pheno subjects
…rors, handle similar failures consistently (neurobagel/bagel-cli#750) * raise BagelValidationError instead of logging + exiting in phenotypic input validations * log independent pheno input validation errors together and refactor age transform error raising * raise BagelFileError instead of calling log_error for input file parsing errors * handle logging and exiting for phenotypic file parsing errors * raise BagelValidationError and BagelResourceError in BIDS steps * handle error with vocab fetching in main command * refactor BIDS validations * create PipelineCatalog class to allow lazy-loading of remote catalog on first access * handle subjects missing from phenotypic data in main command logic * remove leftover utility for checking pipeline catalog availability * standardize handling of resource fetching * rename validate_dataset_description to convey that it returns a validated object * raise BagelValidationError instead of logging + exiting for pipeline-version validation * update assertions and mocks for requested resources in integration tests * update error assertions in tests * test pheno file parsing errors returned together * test app exits when BIDS vocab fetching fails * test harmonize-pheno errors gracefully for age transformation failure * add placeholder dataset description to test of input file parsing errors * separate logging and exiting globally * catch age transformation error more precisely * temporarily pin typer to avoid removed support for click_type from 0.29.0 - fastapi/typer#1831 * test bids2tsv exits gracefully for failed BIDS vocab fetching * test informative error when BIDS subjects don't match pheno subjects
|
@relativityspace-jsmith I understand the frustration of having an upgrade break your CI. Could you open a discussion with a minimal example of your |
|
Hi, thank you for following up. The actual functionality that I needed (the ability to use an enum's names to set the values for an option) is well described by #1572 . I was using But most of my concerns here aren't related to this specific issue or to |
|
Thanks for clarifying. The migration was informed by our developer survey, which showed strong interest in Pydantic and very low use of Click-specific features. I understand the disruption, and the release notes could have been clearer about the removal of Edit: I also edited the release notes with the main relevant changes I could fine (with the help of Codex / Astra). |
|
All, thanks for the discussion here! I suggest to have further follow-up discussions in the actual discussion forum, which will make it easier to track them. Thanks 🙏 |
Meta: marked as a "feature", but definitely also "breaking" !
Description
Make Pydantic a required dependency and rely on it for parameter validation. Picked
>=2.5.3which is the current pin forgithub-actions.Click's
ParamTypehierarchy is now replaced by a three-layer design:TypeDescriptorobjects store static facts about a parameter's type (in the new modulecoercion.py)TypeAdapterobjects are defined in the new moduleadapters.pyRuntimeParamsubclasses own coercion (also defined incoercion.py)Further type-specific functionality is bundled in the new module
param_types.py.How to review this
_click/types.pyandtyper/_types.pyare deletedtyper/param_types.py, thentyper/adapters.py, thentyper/coercion.pytyper/core.pytyper/*.pytyper/_click/*.pyExtended/improved functionality
[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]. Unix timestamps as seconds or milliseconds since the Unix epoch are now also supported.TyperParameter, not quite finished yet with some ugly imports from within_clickbut we'll deal with those in follow-up workTests with same behaviour on
mastertest_bool_convert_validto ensure that the "bool" conversion has remained the same for all kinds of inputs.test_path_resolves, cf point 1) in the Fable review 👇Breaking changes
(more or less in order of breakingness from most to least)
click_typeand open bounds throughmin_openandmax_open. This greatly simplifies the code base while still providing an alternative by settingparserinstead.<list[Eggs|Bacon|Cheese]>(before there was no visual distinction between a single choice, or a list of them).<datetime>". Before, it would show the (only) 3 options, but those are not exhaustive anymore. When the user provides actualformats, those are shown (as before).reprfunctionality ofparam.type. This wasn't really used except for the tests that were recently added in ➖ Vendor Click and streamline Typer's functionality and code base #1774.Anydoes NOT raiseRuntimeError: Type not yet supportedanymore, but instead just falls through and gets a genericTypeAdapter(annotation)Note that as before, nothing in the module
typer/_click(a remnant of the recent vendoring) should be used directly by users and all of it is subject to change in the near future. Any changes in those modules are not considered to be "breaking".Bug fixes (also breaking bwd compat)
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.None(e.g.tuple[str, int, bool]), will fail validation as soon as one of those elements isNone. Our documented example of setting that tuple's default to(None, None, None)is not valid anymore, it should be set toNoneinstead. cf. change todocs_src/multiple_values/options_with_multiple_values/tutorial001_an_py310.py.test_default_infers_param_type.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.datetimetype if no formats are provided by the user (cf ☝️ "Breaking changes")intorfloatas datetime input, to present Unix timestamps as seconds or milliseconds since the Unix epoch? Cf also Fable's concern in point 4 of its review below 👇AI Disclaimer
Cursor was used as a micro-managed junior. Every edit was reviewed & understood by me.
TODO
Parameter.nametyped asstrinstead ofstr | None#1878Follow-up work
typer/_click