From bbcde6d5fafb8a9e5e6ff38e2b29679bdbeadc21 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 27 Apr 2008 07:26:25 +0000 Subject: Take the classes that initialize variables in __slots__ with keyword constructor arguments and make them all derive from a new SlotObject class. (trunk r9994) svn path=/main/branches/2.1.2/; revision=9995 --- bin/emerge | 73 ++++++++++++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 42 deletions(-) (limited to 'bin') diff --git a/bin/emerge b/bin/emerge index 053a3f6a2..8fddb1b1c 100755 --- a/bin/emerge +++ b/bin/emerge @@ -991,14 +991,25 @@ def filter_iuse_defaults(iuse): else: yield flag -class AbstractDepPriority(object): - __slots__ = ("__weakref__", "buildtime", "runtime", "runtime_post") +class SlotObject(object): + __slots__ = ("__weakref__") + def __init__(self, **kwargs): - for myattr in chain(self.__slots__, AbstractDepPriority.__slots__): - if myattr == "__weakref__": + classes = [self.__class__] + while classes: + c = classes.pop() + if c is SlotObject: + continue + classes.extend(c.__bases__) + slots = getattr(c, "__slots__", None) + if not slots: continue - myvalue = kwargs.get(myattr, False) - setattr(self, myattr, myvalue) + for myattr in slots: + myvalue = kwargs.get(myattr, None) + setattr(self, myattr, myvalue) + +class AbstractDepPriority(SlotObject): + __slots__ = ("buildtime", "runtime", "runtime_post") def __lt__(self, other): return self.__int__() < other @@ -1346,28 +1357,14 @@ def show_masked_packages(masked_packages): shown_comments.add(comment) return have_eapi_mask -class Task(object): - __slots__ = ("__weakref__", "_hash_key",) - - def __init__(self, **kwargs): - classes = [self.__class__] - while classes: - c = classes.pop() - if c is Task: - continue - classes.extend(c.__bases__) - slots = getattr(c, "__slots__", None) - if not slots: - continue - for myattr in slots: - myvalue = kwargs.get(myattr, None) - setattr(self, myattr, myvalue) +class Task(SlotObject): + __slots__ = ("_hash_key",) def _get_hash_key(self): - try: - return self._hash_key - except AttributeError: + hash_key = getattr(self, "_hash_key", None) + if hash_key is None: raise NotImplementedError(self) + return hash_key def __eq__(self, other): return self._get_hash_key() == other @@ -1397,9 +1394,8 @@ class Blocker(Task): __slots__ = ("root", "atom", "satisfied") def _get_hash_key(self): - try: - return self._hash_key - except AttributeError: + hash_key = getattr(self, "_hash_key", None) + if hash_key is None: self._hash_key = \ ("blocks", self.root, self.atom) return self._hash_key @@ -1415,9 +1411,8 @@ class Package(Task): self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"]) def _get_hash_key(self): - try: - return self._hash_key - except AttributeError: + hash_key = getattr(self, "_hash_key", None) + if hash_key is None: operation = "merge" if self.onlydeps or self.installed: operation = "nomerge" @@ -1446,9 +1441,8 @@ class Package(Task): class Uninstall(Package): __slots__ = () def _get_hash_key(self): - try: - return self._hash_key - except AttributeError: + hash_key = getattr(self, "_hash_key", None) + if hash_key is None: self._hash_key = \ (self.type_name, self.root, self.cpv, "uninstall") return self._hash_key @@ -1480,16 +1474,11 @@ class SetArg(DependencyArg): self.set = set self.name = self.arg[len(SETPREFIX):] -class Dependency(object): - __slots__ = ("__weakref__", "atom", "blocker", "depth", +class Dependency(SlotObject): + __slots__ = ("atom", "blocker", "depth", "parent", "onlydeps", "priority", "root") def __init__(self, **kwargs): - for myattr in self.__slots__: - if myattr == "__weakref__": - continue - myvalue = kwargs.get(myattr, None) - setattr(self, myattr, myvalue) - + SlotObject.__init__(self, **kwargs) if self.priority is None: self.priority = DepPriority() if self.depth is None: -- cgit v1.2.3-1-g7c22