Skip to content

Commit 2111e74

Browse files
committed
fix(tests): drop stale __contains__ references after ABC removal
Roborev #1761: the ``required = {...}`` set in ``test_program_cache_resource_requires_core_methods`` still contained ``"__contains__"`` after the prior commit removed it from the ABC, which would fail the assertion immediately. Drop it from the required set, add a positive assertion that ``__contains__`` is intentionally NOT abstract (with a comment explaining why), and remove the now-vestigial ``__contains__`` methods from the ``_Empty`` and ``_Tracked`` test subclasses.
1 parent 9b8d2cf commit 2111e74

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

cuda_core/tests/test_program_cache.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ def test_program_cache_resource_requires_core_methods():
2222
required = {
2323
"__getitem__",
2424
"__setitem__",
25-
"__contains__",
2625
"__delitem__",
2726
"__len__",
2827
"clear",
2928
}
3029
assert required <= ProgramCacheResource.__abstractmethods__
30+
# ``__contains__`` is intentionally NOT abstract: the racy
31+
# ``key in cache; data = cache[key]`` idiom should be discouraged
32+
# in favour of ``data = cache.get(key)``.
33+
assert "__contains__" not in ProgramCacheResource.__abstractmethods__
3134

3235

3336
def _build_empty_subclass():
@@ -40,9 +43,6 @@ def __getitem__(self, key):
4043
def __setitem__(self, key, value):
4144
pass
4245

43-
def __contains__(self, key):
44-
return False
45-
4646
def __delitem__(self, key):
4747
raise KeyError(key)
4848

@@ -83,9 +83,6 @@ def __getitem__(self, key):
8383
def __setitem__(self, key, value):
8484
pass
8585

86-
def __contains__(self, key):
87-
return False
88-
8986
def __delitem__(self, key):
9087
raise KeyError(key)
9188

0 commit comments

Comments
 (0)