commit: da4460e341f9d734ff9b3dc49c5873aac3754bb2
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sat Nov 22 20:35:48 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sat Nov 22 20:37:59 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=da4460e3
fix: WeakInstMeta should have no awareness of NotImplementedError, nor
assertions
It's wholy outside it's purview, and that sort of check is from before abc.ABC
era. Anyone doing this, the exception needs to fly. They're breaking the api
contract.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/caching.py | 2 +-
tests/test_caching.py | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/snakeoil/caching.py b/src/snakeoil/caching.py
index da3d6a4..1a1cc29 100644
--- a/src/snakeoil/caching.py
+++ b/src/snakeoil/caching.py
@@ -123,6 +123,6 @@ class WeakInstMeta(type):
*a, **kw
) # type: ignore[attr-defined]
return instance
- except (NotImplementedError, TypeError) as t:
+ except TypeError as t:
warnings.warn(f"caching keys for {cls}, got {t} for a={a},
kw={kw}")
return super(WeakInstMeta, cls).__call__(*a, **kw)
diff --git a/tests/test_caching.py b/tests/test_caching.py
index 5524c8b..95bdc57 100644
--- a/tests/test_caching.py
+++ b/tests/test_caching.py
@@ -1,5 +1,7 @@
-import pytest
import gc
+
+import pytest
+
from snakeoil.caching import WeakInstMeta
@@ -116,10 +118,9 @@ class TestWeakInstMeta:
assert weak_inst([]) is not weak_inst([])
assert weak_inst.counter == 2
- for x in (TypeError, NotImplementedError):
- assert weak_inst(RaisingHashForTestUncachable(x)) is not weak_inst(
- RaisingHashForTestUncachable(x)
- )
+ assert weak_inst(RaisingHashForTestUncachable(TypeError)) is not
weak_inst(
+ RaisingHashForTestUncachable(TypeError)
+ )
@pytest.mark.filterwarnings("error::UserWarning")
def test_uncachable_warning_msg(self):
@@ -131,9 +132,8 @@ class TestWeakInstMeta:
def __hash__(self):
raise self.error
- for x in (TypeError, NotImplementedError):
- with pytest.raises(UserWarning):
- weak_inst(RaisingHashForTestUncachableWarnings(x))
+ with pytest.raises(UserWarning):
+ weak_inst(RaisingHashForTestUncachableWarnings(TypeError))
def test_hash_collision(self):
class BrokenHash: