diff options
author | Zac Medico <zmedico@gentoo.org> | 2012-02-17 14:31:37 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2012-02-17 14:31:37 -0800 |
commit | 17f1186cb6788c8978b8d231393a03736edc2dfd (patch) | |
tree | 93584690f4fc5cd7485a65578a039298ece23fc7 | |
parent | 4d4e590947553d7d57cc7d303d5d6a9a2edfd948 (diff) | |
download | portage-17f1186cb6788c8978b8d231393a03736edc2dfd.tar.gz portage-17f1186cb6788c8978b8d231393a03736edc2dfd.tar.bz2 portage-17f1186cb6788c8978b8d231393a03736edc2dfd.zip |
SlotObject: validate __slots__ and keyword args
-rw-r--r-- | pym/_emerge/SlotObject.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/pym/_emerge/SlotObject.py b/pym/_emerge/SlotObject.py index fdc6f35ad..a59dfc199 100644 --- a/pym/_emerge/SlotObject.py +++ b/pym/_emerge/SlotObject.py @@ -1,4 +1,4 @@ -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 class SlotObject(object): @@ -15,9 +15,18 @@ class SlotObject(object): if not slots: continue for myattr in slots: - myvalue = kwargs.get(myattr, None) + myvalue = kwargs.pop(myattr, None) + if myvalue is None and getattr(self, myattr, None) is not None: + raise AssertionError( + "class '%s' duplicates '%s' value in __slots__ of base class '%s'" % + (self.__class__.__name__, myattr, c.__name__)) setattr(self, myattr, myvalue) + if kwargs: + raise TypeError( + "'%s' is an invalid keyword argument for this constructor" % + (next(iter(kwargs)),)) + def copy(self): """ Create a new instance and copy all attributes |