python-diskcache
python-diskcache copied to clipboard
Support pathlib.Path objects as first parameter
Thanks for the effort that has been put into this library, it's clear a lot of attention to detail is involved.
On my very first attempt to use this, I wanted to pass in a data directory:
from pathlib import Path
import diskcache
data_dpath = Path(__file__).parent / data
config = diskcache.Index(data_dpath)
Traceback (most recent call last):
File "/home/rsyring/projects/huepy-pkg/hue.py", line 17, in <module>
config = diskcache.Index(DATA_DPATH)
File "/home/rsyring/tmp/virtualenvs/huepy/lib/python3.9/site-packages/diskcache/persistent.py", line 670, in __init__
self.update(*args, **kwargs)
File "/usr/lib/python3.9/_collections_abc.py", line 945, in update
for key, value in other:
TypeError: 'PosixPath' object is not iterable
Digging into the source I realized I needed to pass a string instead, which is fair and actually what the docs say to do. I'm just so used to thinking of paths in terms of pathlib now, that it took me a bit to figure out the problem. But with the Python stdlib moving to support "path like" objects which include pathlib.Path, maybe diskcache could as well?
Thanks again.