From 7832c4dbe43e73b93d7680bf67c22a3322684171 Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Sat, 24 Oct 2026 21:22:35 -0600 Subject: [PATCH] =?UTF-8?q?fix(cacher):=20treat=20an=20expiry=20within=201?= =?UTF-8?q?=20=C2=B5s=20of=20now=20as=20expired?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit datetime rounds the expiry to the microsecond, which can land past a coarse time.time() tick (15.6 ms on Windows) and flake test_zero_seconds_expires_now. --- unshackle/core/cacher.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unshackle/core/cacher.py b/unshackle/core/cacher.py index 04aa8043..d5b21dd0 100644 --- a/unshackle/core/cacher.py +++ b/unshackle/core/cacher.py @@ -49,8 +49,11 @@ class Cacher: @property def expired(self) -> bool: - """Compare as unix time: wall-clock comparison is wrong for an hour at each DST change.""" - return bool(self.expiration and self.expiration.timestamp() < time.time()) + """ + Compare as unix time: wall-clock comparison is wrong for an hour at each DST change. + The 1 µs allowance covers datetime rounding the expiry up past a coarse clock (15.6 ms on Windows). + """ + return bool(self.expiration and self.expiration.timestamp() < time.time() + 1e-6) def get(self, key: str, version: int = 1) -> Cacher: """