From: Zac Medico Date: Mon, 28 Jul 2008 05:34:07 +0000 (-0000) Subject: Create a SlotDict constructor which can take an optional positional arg that X-Git-Tag: v2.2_rc4~6 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=cde46b372b6fa08174714f3b3443767528d3cd9c;p=portage.git Create a SlotDict constructor which can take an optional positional arg that is passed to the update() method (similar to the dict constructor), and also pass keyword arguments into the update() method if any are given. This makes it possible to use the constructor similarly to the way that the _emerge.SlotObject constructor is used. svn path=/main/trunk/; revision=11230 --- diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index d0ca487f0..75f97d6ae 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -142,6 +142,19 @@ def slot_dict_class(keys, prefix="_val_"): __slots__ = ("__weakref__",) + \ tuple(prefix + k for k in allowed_keys) + def __init__(self, *args, **kwargs): + + if len(args) > 1: + raise TypeError( + "expected at most 1 positional argument, got " + \ + repr(1 + len(args))) + + if args: + self.update(args[0]) + + if kwargs: + self.update(kwargs) + def __iter__(self): for k, v in self.iteritems(): yield k