提交 f7898c43 authored 作者: Michael Osthege's avatar Michael Osthege 提交者: Brandon T. Willard

Support and test passing a dict as first argument to change_flags

上级 082d02f0
......@@ -158,6 +158,9 @@ def test_config_context():
with configparser.change_flags(test_config_context="new_value"):
assert root.test_config_context == "new_value"
with root.change_flags({"test_config_context": "new_value2"}):
assert root.test_config_context == "new_value2"
assert root.test_config_context == "new_value"
assert root.test_config_context == "test_default"
......
......@@ -23,10 +23,11 @@ class TheanoConfigWarning(Warning):
class _ChangeFlagsDecorator:
def __init__(self, *args, _root=None, **kwargs):
# the old API supported passing a dict as the first argument:
args = dict(args)
args.update(kwargs)
self.confs = {k: _root._config_var_dict[k] for k in args}
self.new_vals = args
if args:
assert len(args) == 1 and isinstance(args[0], dict)
kwargs = dict(**args[0], **kwargs)
self.confs = {k: _root._config_var_dict[k] for k in kwargs}
self.new_vals = kwargs
self._root = _root
def __call__(self, f):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论