Description
🚀 The feature
Add support for pathlib.Path
in addition to str
for any functions taking files or directories as input.
According to PEP-519, the type hints would look like:
Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
Motivation, pitch
TorchGeo is planning on adding support for this. However, we use a lot of utility functions like download_url
that only accept str
at the moment.
This was also requested in #7721 for a more limited scope, so users are clearly trying to use this.
It seems that most of the code in torchvision/prototype
already uses pathlib? Maybe it's just a matter of waiting until those prototypes become the default. But I don't see any progress yet for porting the utility functions we use.
Alternatives
Our workaround for now is to convert all Paths to strings before calling download_url
, but that kind of defeats the purpose of supporting Paths if we always immediately convert them to strings.
Additional context
Cross linking to microsoft/torchgeo#1616 and microsoft/torchgeo#1731
P.S. We would be willing to contribute this for the utilities we use in TorchGeo, but probably don't have the time/energy to contribute this for all of torchvision. Let me know what you think.
cc @pmeier