commit: dffd05f275271d7e09f5f589274cb1113e5d3dd0
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sat Nov 22 20:40:55 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sat Nov 22 20:40:59 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=dffd05f2
chore: tweak WeakInstMeta to be clear hashed arguments are required
This code historically threw a warning since we couldn't do static
analysis when I wrote it, we can now, thus the tolerance for warning
on non-hashables is going to be removed once annotations is at the
point it's enforcable.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/caching.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/snakeoil/caching.py b/src/snakeoil/caching.py
index 1a1cc29..62268ba 100644
--- a/src/snakeoil/caching.py
+++ b/src/snakeoil/caching.py
@@ -55,6 +55,7 @@ Simple usage example:
__all__ = ("WeakInstMeta",)
import functools
+import typing
import warnings
from weakref import WeakValueDictionary
@@ -105,9 +106,11 @@ class WeakInstMeta(type):
):
scope["__slots__"] = tuple(scope["__slots__"]) + ("__weakref__",)
- return super().__new__(cls, name, bases, scope, **kwds)
+ new_cls = super().__new__(cls, name, bases, scope, **kwds)
+ new_cls.__annotations__["__inst_dict__"] = dict[typing.Hashable,
typing.Any]
+ return new_cls
- def __call__(cls, *a, **kw):
+ def __call__(cls, *a: typing.Hashable, **kw: typing.Hashable):
"""disable caching via disable_inst_caching=True"""
# This is subtle, but note that this explictly passes
"disable_inst_caching" down to the class
# if the class itself has disabled caching. This is a debatable
design- it means any