Open MarcBresson opened 5 months ago
Hi @MarcBresson,
Thanks for the feature request! This looks similar to https://github.com/pydantic/pydantic-extra-types/issues/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!
Thanks moving the issue
It is similar in the fact that it is about paths, but it is a new type that has not been suggested in #149 .
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 mode