aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Harring <ferringb@gmail.com>2024-01-15 20:14:31 -0800
committerBrian Harring <ferringb@gmail.com>2024-01-23 00:52:08 -0800
commitb25406371ff563b7f7f845f2976a8270149a4cff (patch)
tree782248a2c74d730a64d997a88b0aefe2eb9dd61a
parentrefactor: leverage ABC protections for prototype.tree (diff)
downloadpkgcore-b25406371ff563b7f7f845f2976a8270149a4cff.tar.gz
pkgcore-b25406371ff563b7f7f845f2976a8270149a4cff.tar.bz2
pkgcore-b25406371ff563b7f7f845f2976a8270149a4cff.zip
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@gmail.com>
-rw-r--r--src/pkgcore/repository/prototype.py18
1 files 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):