Closed Stannislav closed 2 years ago
We often pass paths as function arguments, which leads to following types and structures:
def f(path: str | pathlib.Path): path = pathlib.Path(path) ...
The constructor of pathlib.Path expects arguments of type str | os.PathLike[str], where os.PathLike is a broad abstract base class. So we can also broaden the type of the function f by writing
pathlib.Path
str | os.PathLike[str]
os.PathLike
f
def f(path: str | os.PathLike): path = pathlib.Path(path) ...
There is already an alias for this union defined in morphoclass.types: StrPath, so one just needs to start using it. Then we'd have
morphoclass.types
StrPath
def f(path: StrPath): path = pathlib.Path(path) ...
We often pass paths as function arguments, which leads to following types and structures:
The constructor of
pathlib.Path
expects arguments of typestr | os.PathLike[str]
, whereos.PathLike
is a broad abstract base class. So we can also broaden the type of the functionf
by writingThere is already an alias for this union defined in
morphoclass.types
:StrPath
, so one just needs to start using it. Then we'd have