diskcache-stubs

raw JSON →
5.6.3.6.20240818 verified Mon Apr 27 auth: no python

Type stubs for the diskcache library, enabling type checking and IDE autocompletion. Current version 5.6.3.6.20240818, updated infrequently to match diskcache releases.

pip install diskcache-stubs
error ImportError: cannot import name 'Cache' from 'diskcache'
cause diskcache not installed; only stubs are installed.
fix
pip install diskcache
error ModuleNotFoundError: No module named 'diskcache_stubs'
cause Attempting to import from diskcache_stubs directly or missing installation.
fix
Import from diskcache; ensure diskcache-stubs is installed for type hints.
error TypeError: 'module' object is not callable
cause Trying to use diskcache as a class instead of importing subclasses.
fix
Use: from diskcache import Cache; cache = Cache('/tmp')
gotcha Installing diskcache-stubs does not install diskcache. You must install diskcache separately.
fix pip install diskcache diskcache-stubs
gotcha Do not import directly from diskcache_stubs. Import from the diskcache package.
fix from diskcache import Cache
gotcha The stubs version includes the diskcache version (e.g., 5.6.3) and a stub patch number. Ensure compatibility by matching the diskcache major.minor.patch.
fix Check diskcache version: pip show diskcache; then install matching stubs: pip install diskcache-stubs==5.6.3.x
deprecated Old versions of diskcache-stubs (<5.6.3) may have incomplete type annotations for newer diskcache features.
fix Upgrade to latest: pip install --upgrade diskcache-stubs

Create a disk cache, set and get a value. Type hints will be available after installing diskcache-stubs.

from diskcache import Cache
cache = Cache('/tmp/my_cache')
cache.set('key', 'value')
print(cache.get('key'))