Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

diskcache-community forked from DiskCache at upstream commit ebfa37c (3 March 2024), two commits after the 5.6.3 release. Each entry names the pull request in this repository. Imported upstream pull requests are referenced by number, and their commits keep their original authors in the git history.

## Unreleased

### Fixes

- `incr` and `decr` on `Cache` and `FanoutCache` type-check with `default=None`, which makes a missing key raise `KeyError`: the stubs typed `default` as `int`, so type checkers rejected the call. `tox -e mypy` now also checks `tests/typecheck_stubs.py`, a file of calls that must type-check against the stubs (PR #41).

## 5.8.2 (2026-11-02)

Adds `SafeJSONDisk` and `SafeDisk.with_numpy()`, keeps float NaN values, and makes `get` and `set` faster. The `cache.db` schema and the file layout are unchanged.
Expand Down
12 changes: 10 additions & 2 deletions diskcache_community/_types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ class BaseCache(Protocol):
retry: bool = ...,
) -> bool: ...
def incr(
self, key: Any, delta: int = ..., default: int = ..., retry: bool = ...
self,
key: Any,
delta: int = ...,
default: int | None = ...,
retry: bool = ...,
) -> int: ...
def decr(
self, key: Any, delta: int = ..., default: int = ..., retry: bool = ...
self,
key: Any,
delta: int = ...,
default: int | None = ...,
retry: bool = ...,
) -> int: ...
def get( # noqa: PLR0913
self,
Expand Down
22 changes: 22 additions & 0 deletions tests/typecheck_stubs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Calls that must type-check against the shipped stubs.

``tox -e mypy`` checks this file; pytest does not collect it.
"""

import diskcache_community as dc


def incr_without_default(cache: dc.Cache, key: str) -> int:
return cache.incr(key, 1, default=None)


def decr_without_default(cache: dc.Cache, key: str) -> int:
return cache.decr(key, 1, default=None)


def fanout_incr_without_default(cache: dc.FanoutCache, key: str) -> int:
return cache.incr(key, 1, default=None)


def fanout_decr_without_default(cache: dc.FanoutCache, key: str) -> int:
return cache.decr(key, 1, default=None)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commands=isort --check {toxinidir}/diskcache_community {toxinidir}/tests
deps=isort

[testenv:mypy]
commands=mypy {toxinidir}/diskcache_community
commands=mypy {toxinidir}/diskcache_community {toxinidir}/tests/typecheck_stubs.py
deps=mypy

[testenv:pylint]
Expand Down
Loading