In LazyItemsDict, avoid storing empty lists and dicts when no positional or
authorZac Medico <zmedico@gentoo.org>
Mon, 23 Feb 2009 20:52:10 +0000 (20:52 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 23 Feb 2009 20:52:10 +0000 (20:52 -0000)
keyword arguments are given.

svn path=/main/trunk/; revision=12700

pym/portage/util.py

index a8dbf6c277f1f06c1228fa77a83725e381e4b663..2cb14b34d1848c52aeac69d4f141085831c9012d 100644 (file)
@@ -1072,6 +1072,10 @@ class LazyItemsDict(dict):
        def addLazyItem(self, item_key, value_callable, *pargs, **kwargs):
                """Add a lazy item for the given key.  When the item is requested,
                value_callable will be called with *pargs and **kwargs arguments."""
+               if not pargs:
+                       pargs = None
+               if not kwargs:
+                       kwargs = None
                self.lazy_items[item_key] = (value_callable, pargs, kwargs)
                # make it show up in self.keys(), etc...
                dict.__setitem__(self, item_key, None)
@@ -1094,6 +1098,10 @@ class LazyItemsDict(dict):
        def __getitem__(self, item_key):
                if item_key in self.lazy_items:
                        value_callable, pargs, kwargs = self.lazy_items[item_key]
+                       if pargs is None:
+                               pargs = ()
+                       if kwargs is None:
+                               kwargs = {}
                        return value_callable(*pargs, **kwargs)
                else:
                        return dict.__getitem__(self, item_key)