commit 380809f02e10f4f5b648707e88aa9cb31f3e7a44 Author: Damian Johnson atagar@torproject.org Date: Sat Jun 14 14:26:26 2014 -0700
Changed @uses_settings to only provide config if used
Changing our conf module's @uses_settings decorators to only provide a 'config' argument if the funcion we're decorating accepts one. This avoids stacktraces like...
Traceback (most recent call last): File "./run_tests.py", line 79, in <module> main() File "/usr/lib/python2.7/stem/util/conf.py", line 282, in wrapped return func(*args, config = config, **kwargs) TypeError: main() got an unexpected keyword argument 'config' --- docs/change_log.rst | 1 + stem/util/conf.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst index 2159c28..6126cc9 100644 --- a/docs/change_log.rst +++ b/docs/change_log.rst @@ -43,6 +43,7 @@ The following are only available within Stem's `git repository * **Utilities**
* Added support for directories to :func:`stem.util.conf.Config.load`. + * Changed :func:`stem.util.conf.uses_settings` to only provide a 'config' keyword arument if the decorated function would accept it.
* **Interpreter**
diff --git a/stem/util/conf.py b/stem/util/conf.py index 57bc724..18b0df4 100644 --- a/stem/util/conf.py +++ b/stem/util/conf.py @@ -157,6 +157,7 @@ Here's an expanation of what happened... +- get_value - provides the value for a given key as a string """
+import inspect import os import threading
@@ -247,6 +248,10 @@ def uses_settings(handle, path, lazy_load = True): that require settings to be loaded. Functions with this annotation will be provided with the configuration as its 'config' keyword argument.
+ .. versionchanged:: 1.3.0 + Omits the 'config' argument if the funcion we're decorating doesn't accept + it. + ::
uses_settings = stem.util.conf.uses_settings('my_app', '/path/to/settings.cfg') @@ -279,7 +284,10 @@ def uses_settings(handle, path, lazy_load = True): config.load(path) config.set('settings_loaded', 'true')
- return func(*args, config = config, **kwargs) + if 'config' in inspect.getargspec(func)[0]: + return func(*args, config = config, **kwargs) + else: + return func(*args, **kwargs)
return wrapped
tor-commits@lists.torproject.org