commit: caafeeefe1d4fa3b22eba164d2084babd520db0f
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Tue Oct 28 00:28:11 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Tue Oct 28 10:07:36 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=caafeeef
feat!: turn down slot_shadowing test defaults
This was from early days of limited memory and slow python, and
when snakeoil/pkgcore/pkgcheck releases were tightly coupled.
These days, there's no reason to explode if a slot_shadowing is
found- instead if should only go 'boom' if it's explicitly told
to do so.
For snakeoil, this is enforced since our dependency chain is
minimal. For anything downstream, this isn't unless they enable
it.
Note that strictly speaking, this breaks semver behavior for
tests- what would've failed before now won't. Downstream
consumers are all clean so this is a non issue however.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/test/slot_shadowing.py | 19 +++++++++++++++----
tests/test_slot_shadowing.py | 2 +-
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/snakeoil/test/slot_shadowing.py
b/src/snakeoil/test/slot_shadowing.py
index abb8e09..fa3b683 100644
--- a/src/snakeoil/test/slot_shadowing.py
+++ b/src/snakeoil/test/slot_shadowing.py
@@ -1,3 +1,5 @@
+import warnings
+
import pytest
from . import mixins
@@ -7,6 +9,7 @@ class SlotShadowing(mixins.TargetedNamespaceWalker,
mixins.SubclassWalker):
target_namespace = "snakeoil"
err_if_slots_is_str = True
err_if_slots_is_mutable = True
+ strict = False
def recurse_parents(self, kls, seen=None):
if not seen:
@@ -54,7 +57,7 @@ class SlotShadowing(mixins.TargetedNamespaceWalker,
mixins.SubclassWalker):
if isinstance(slots, str):
if self.err_if_slots_is_str:
- pytest.fail(
+ self.report_issue(
f"cls {kls!r}; slots is {slots!r} (should be a tuple or
list)"
)
slots = (slots,)
@@ -64,20 +67,28 @@ class SlotShadowing(mixins.TargetedNamespaceWalker,
mixins.SubclassWalker):
if not isinstance(slots, tuple):
if self.err_if_slots_is_mutable:
- pytest.fail(f"cls {kls!r}; slots is {slots!r}- - should be a
tuple")
+ self.report_issue(
+ f"cls {kls!r}; slots is {slots!r}- - should be a tuple"
+ )
slots = tuple(slots)
if slots is None or (slots and slots in raw_slottings):
# we do a bool on slots to ignore (); that's completely valid
# this means that the child either didn't define __slots__, or
# daftly copied the parents... thus defeating the purpose.
- pytest.fail(
+ self.report_issue(
f"cls {kls!r}; slots is {slots!r}, seemingly inherited from "
f"{raw_slottings[slots]!r}; the derivative class should be
__slots__ = ()"
)
for slot in slots:
if slot in slotting:
- pytest.fail(
+ self.report_issue(
f"cls {kls!r}; slot {slot!r} was already defined at
{slotting[slot]!r}"
)
+
+ def report_issue(self, message):
+ if self.strict:
+ pytest.fail(message)
+ else:
+ warnings.warn(f"slot_shadowing detected: {message}")
diff --git a/tests/test_slot_shadowing.py b/tests/test_slot_shadowing.py
index 5ba3fa0..589d6ca 100644
--- a/tests/test_slot_shadowing.py
+++ b/tests/test_slot_shadowing.py
@@ -2,4 +2,4 @@ from snakeoil.test.slot_shadowing import SlotShadowing
class Test_slot_shadowing(SlotShadowing):
- pass
+ strict = True