Open unicodestrangely opened 1 week ago
Indeed, looks like a bug! Help welcome here - should be fix in the _std_types_schema.py
file.
@sydney-runkle I can take this one.
@sydney-runkle so do we expect any certain behaviors that different from os.PathLike
for the os.PathLike[str], os.PathLike[bytes]
type ?
And also what are the limit for xxx
in os.PathLike[xxx]
? or just bytes
and str
@nix010,
Let's just start with bytes
and str
for now. I'm not aware of special behaviors that we need to account for at the moment, though we'll probably want to perform validation on the data relevant to the type that PathLike
is being parametrized with!
I think os.PathLike[Any]
should be supported as well.
Omitting the generic notation equals Any
, so os.PathLike
is the same as os.PathLike[Any]
.
@unicodestrangely I'm a bit hesitate with let's say the case is os.PathLike[Any]
and the input is int
, should the code raises validation error ?
import os
from typing import Any
from pydantic import BaseModel
class Foo(BaseModel):
field: os.PathLike[Any]
Foo(field=12345) #<-- Should this raised validation error ?
@sydney-runkle I'm not sure if the change is align wiht what is expected but made #9764 anyway to see if it on the right direction!
@nix010 Yes, it should raise an error. os.PathLike
(even [Any]
) must have an __fspath__
method (docs).
Initial Checks
Description
Works with plain
os.PathLike
. Error withos.PathLike[str]
,os.PathLike[bytes]
,os.PathLike[Any]
.Example Code
Python, Pydantic & OS Version