For some reaosn, FileUrl format fails pydantic validation for AnyUrl
Simple example:
from pydantic import FileUrl, AnyUrl, BaseModel
from typing import Union
class GenericModel(BaseModel):
v: AnyUrl # Failure case
class FileModel(BaseModel):
v: FileUrl
class DontCareModel(BaseModel):
v: Union[AnyUrl, FileUrl]
value = 'file:///foo/bar'
try:
# This don't work on files for some reason
GenericModel(v=value) # Fails
except Exception as err:
print(err)
model = FileModel(v=value)
assert model.v == value
test_model = DontCareModel(v=value)
assert model.v == value
print("success!")
How I did it
Redefine as AnyUrl = Union[_AnyUrl, FileUrl]
How to verify it
Can now have file URL in manifest. See tests.
Checklist
[ ] Passes all linting checks (pre-commit and CI jobs)
[ ] New test cases have been added and are passing
[ ] Documentation has been updated
[ ] PR title follows Conventional Commit standard (will be automatically included in the changelog)
What I did
For some reaosn,
FileUrl
format fails pydantic validation forAnyUrl
Simple example:How I did it
Redefine as
AnyUrl = Union[_AnyUrl, FileUrl]
How to verify it
Can now have file URL in manifest. See tests.
Checklist