commit:     b25406371ff563b7f7f845f2976a8270149a4cff
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Tue Jan 16 04:14:31 2024 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 23 08:52:08 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=b2540637

refactor: loosen prototype.tree._get_* requirements, add typing.

This moves the burden of derivatives having to ensure they return
immutables, instead this is handled by the internals of prototype.tree
since it already partially was.

This change basically makes it easier to write generators for
cat/pkg/ver listing.

For existing implementations returning immutable objects this has
no impact; `t=(1,2);assert t is tuple(t)` for example, and the
same holds for frozenset.

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

 src/pkgcore/repository/prototype.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/pkgcore/repository/prototype.py 
b/src/pkgcore/repository/prototype.py
index e69af82ff..656f8e556 100644
--- a/src/pkgcore/repository/prototype.py
+++ b/src/pkgcore/repository/prototype.py
@@ -54,7 +54,7 @@ class PackageMapping(DictMixin):
             return o
         if key not in self._parent:
             raise KeyError(key)
-        self._cache[key] = vals = self._pull_vals(key)
+        self._cache[key] = vals = tuple(self._pull_vals(key))
         return vals
 
     def keys(self):
@@ -79,7 +79,7 @@ class VersionMapping(DictMixin):
             return o
         if not key[1] in self._parent.get(key[0], ()):
             raise KeyError(key)
-        val = self._pull_vals(key)
+        val = tuple(self._pull_vals(key))
         self._cache[key] = val
         return val
 
@@ -141,18 +141,20 @@ class tree(abc.ABC):
         raise NotImplementedError(self, "configure")
 
     @abc.abstractmethod
-    def _get_categories(self):
-        """this must return a list, or sequence"""
+    def _get_categories(self) -> frozenset[str] | typing.Iterable[str]:
+        """this must return an iterable or tuple of this repo's categories"""
         raise NotImplementedError(self, "_get_categories")
 
     @abc.abstractmethod
-    def _get_packages(self, category):
-        """this must return a list, or sequence"""
+    def _get_packages(self, category: str) -> tuple[str] | 
typing.Iterable[str]:
+        """Receives category and must return the packages of that cat.  
Converted to tuple"""
         raise NotImplementedError(self, "_get_packages")
 
     @abc.abstractmethod
-    def _get_versions(self, package):
-        """this must return a list, or sequence"""
+    def _get_versions(
+        self, package: tuple[str, str]
+    ) -> tuple[str] | typing.Iterable[str]:
+        """Receives (cat/pkg) and must return the cp versions.  Converted to 
tuple"""
         raise NotImplementedError(self, "_get_versions")
 
     def __getitem__(self, cpv):

Reply via email to