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
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
Working with Paths is fairly common and I usually end up writing my own field validator over and over again because the type I want is missing. I would like to see the Path types in pydantic extended with some more potentially useful types:
ExistingPath - Union[FilePath, DirectoryPath]
ResolvedFilePath - A file that get's resolved (pathlib.Path.expanduser().resolve()) by pydantic before returning
ResolvedDirectoryPath - A directory that get's resolved (pathlib.Path.expanduser().resolve()) by pydantic before returning
My current solution is to just write a field validator:
@field_validator("path_a", "path_b")@classmethoddefresolve_path(cls, path: Path) ->Path:
"""Resolve all given Path fields"""returnpath.expanduser().resolve()
Thanks for the feature request. I'm sure many people would appreciate extended support for these types. The right place for these, though, is in pydantic-extra-types. I'll transfer this issue over there 👍.
Initial Checks
Description
Working with Paths is fairly common and I usually end up writing my own field validator over and over again because the type I want is missing. I would like to see the Path types in pydantic extended with some more potentially useful types:
ExistingPath
-Union[FilePath, DirectoryPath]
ResolvedFilePath
- A file that get's resolved (pathlib.Path.expanduser().resolve()
) by pydantic before returningResolvedDirectoryPath
- A directory that get's resolved (pathlib.Path.expanduser().resolve()
) by pydantic before returningResolvedPath
-Union[ResolvedFilePath, ResolvedDirectoryPath]
My current solution is to just write a field validator:
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: