You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, a validation error will be thrown if the user wants to create an entire new tree.
Proposal
The already existing NewPath checks that the path does not exist but its parent does exist. A type that only checks for the first condition would be great.
Here is my code to add this type if anyone is interested:
defnew_path_and_parents(path: Path) ->Path:
"Check if a specified path does not already exist"assertnotpath.exists(), f"{path} already exists"returnpathNewPathAndParents: TypeAlias=Annotated[Path, AfterValidator(new_path_and_parents)]
Non relevant additional proposal
I also had the intention to suggest an annotation to create a folder directly so that if the folder is new, it is created. But because Pydantic validation happens all at once, if a validation fails, the folder would still be created and NewPathAndParents would fail at the next run. Here is the implementation if anyone wants it:
Thanks for the feature request! This looks similar to #149, at a first glance. I'm going to move this issue to pydantic-extra-types. I certainly think greater support for path-like types could fit well there!
Initial Checks
Description
Hello,
I am using Pydantic to validate some path the user is supposed to give:
However, a validation error will be thrown if the user wants to create an entire new tree.
Proposal
The already existing
NewPath
checks that the path does not exist but its parent does exist. A type that only checks for the first condition would be great.Here is my code to add this type if anyone is interested:
Non relevant additional proposal
I also had the intention to suggest an annotation to create a folder directly so that if the folder is new, it is created. But because Pydantic validation happens all at once, if a validation fails, the folder would still be created and
NewPathAndParents
would fail at the next run. Here is the implementation if anyone wants it:Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: