commit:     e696da62fb6b804517281f48322922105548e4c7
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Nov 30 22:29:35 2025 +0000
Commit:     Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Nov 30 22:34:56 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=e696da62

chore: add more slotting and annotations

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 src/snakeoil/constraints.py       | 6 ++++++
 src/snakeoil/test/code_quality.py | 5 ++++-
 tests/test_code_quality.py        | 3 +--
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/snakeoil/constraints.py b/src/snakeoil/constraints.py
index 0dd8ffc..57b06ad 100644
--- a/src/snakeoil/constraints.py
+++ b/src/snakeoil/constraints.py
@@ -15,6 +15,8 @@ Usage examples:
 >>>     print(f"x={solution['x']}, y={solution['y']}, z={solution['z']}")
 """
 
+__all__ = ("Constraint", "Problem")
+
 from collections import defaultdict
 from typing import Any, Iterable, Protocol
 
@@ -36,6 +38,8 @@ class Constraint(Protocol):
 
 
 class _Domain(list):
+    __slots__ = ("_hidden", "_states")
+
     def __init__(self, items: Iterable[Any]):
         super().__init__(items)
         self._hidden = []
@@ -76,6 +80,8 @@ class Problem:
         single value from it's domain.
     """
 
+    __slots__ = ("variables", "constraints", "vconstraints")
+
     def __init__(self):
         self.variables: dict[str, _Domain] = {}
         self.constraints: list[tuple[Constraint, frozenset[str]]] = []

diff --git a/src/snakeoil/test/code_quality.py 
b/src/snakeoil/test/code_quality.py
index f6e2397..3899e09 100644
--- a/src/snakeoil/test/code_quality.py
+++ b/src/snakeoil/test/code_quality.py
@@ -94,7 +94,10 @@ class ParameterizeBase(typing.Generic[T], abc.ABC):
 
 class Slots(ParameterizeBase[type]):
     disable_str: typing.Final = "__slotting_intentionally_disabled__"
-    ignored_subclasses: tuple[type, ...] = (Exception,)
+    ignored_subclasses: tuple[type, ...] = (
+        Exception,
+        typing.Protocol,  # pyright: ignore[reportAssignmentType]
+    )
 
     tests_to_parameterize = (
         "test_shadowing",

diff --git a/tests/test_code_quality.py b/tests/test_code_quality.py
index f418071..b5bb87e 100644
--- a/tests/test_code_quality.py
+++ b/tests/test_code_quality.py
@@ -9,7 +9,6 @@ class TestSlots(code_quality.Slots):
         "snakeoil.chksum",
         "snakeoil.cli.arghparse",
         "snakeoil.compression",
-        "snakeoil.constraints",
         "snakeoil.contexts",
         "snakeoil.data_source",  # oofta on that class, py2k/py3k transition 
was brutal on that one.
         "snakeoil.demandload",  # needs to be rewritten to descriptor protocol 
in particular
@@ -18,11 +17,11 @@ class TestSlots(code_quality.Slots):
         "snakeoil.formatters",
         "snakeoil.process",
         "snakeoil.stringio",
+        "snakeoil.struct_compat",
         "snakeoil.tar",
         "snakeoil.test",
         "snakeoil.tools",  # this is CLI stuff which a lot of it intentionally 
avoids snakeoil internals
     )
-    ignored_subclasses = (Exception,)
     strict = True
 
 

Reply via email to