fix(cacher): treat an expiry within 1 µs of now as expired

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.
This commit is contained in:
imSp4rky
2026-10-24 21:22:35 -06:00
parent d0f9307506
commit 7832c4dbe4
+5 -2
View File
@@ -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:
"""