diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2014-12-26 13:52:31 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2014-12-26 13:52:49 -0800 |
commit | 860f834aad0d6503057693b894d9996143dde312 (patch) | |
tree | 6c9b5d65e5d495d42942ec2a687f27b248a8ca7c /lib/spack/llnl/util/lang.py | |
parent | 9dabcc870385de329b9fcb6986d5d6688fa7dca8 (diff) | |
download | spack-860f834aad0d6503057693b894d9996143dde312.tar.gz spack-860f834aad0d6503057693b894d9996143dde312.tar.bz2 spack-860f834aad0d6503057693b894d9996143dde312.tar.xz spack-860f834aad0d6503057693b894d9996143dde312.zip |
spack graph allows plotting specific packages.
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r-- | lib/spack/llnl/util/lang.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py index 049d158c6d..db15da0506 100644 --- a/lib/spack/llnl/util/lang.py +++ b/lib/spack/llnl/util/lang.py @@ -269,6 +269,28 @@ def in_function(function_name): del stack +def check_kwargs(kwargs, fun): + """Helper for making functions with kwargs. Checks whether the kwargs + are empty after all of them have been popped off. If they're + not, raises an error describing which kwargs are invalid. + + Example:: + + def foo(self, **kwargs): + x = kwargs.pop('x', None) + y = kwargs.pop('y', None) + z = kwargs.pop('z', None) + check_kwargs(kwargs, self.foo) + + # This raises a TypeError: + foo(w='bad kwarg') + """ + if kwargs: + raise TypeError( + "'%s' is an invalid keyword argument for function %s()." + % (next(kwargs.iterkeys()), fun.__name__)) + + class RequiredAttributeError(ValueError): def __init__(self, message): super(RequiredAttributeError, self).__init__(message) |