【发布时间】:2021-06-29 14:10:33
【问题描述】:
我有一个使用pydantic 和Path 字段构建的设置类。我需要这条路径作为 Unix 路径,因为它是在数据湖中导航
class Settings(BaseSettings):
DATALAKE_MODEL_RESULT_PATH: Path
上述类的问题是,例如,如果我在 Windows 上,即使在 dotenv 文件中编写为 Unix(Path 类),该路径也会被视为 Windows 路径。
所以我尝试了
class Settings(BaseSettings):
DATALAKE_MODEL_RESULT_PATH: PurePosixPath
但 pydantic 不认识它
ValidationError: 1 validation error for Settings
DATALAKE_MODEL_RESULT_PATH
instance of PurePosixPath expected (type=type_error.arbitrary_type; expected_arbitrary_type=PurePosixPath)
也许我需要一个自定义字段?验证器?
【问题讨论】: