提交 594dbd74 authored 作者: affanv14's avatar affanv14

Fix bug caused when setting default value in Param

上级 9b0f65a8
...@@ -749,6 +749,12 @@ class Function(object): ...@@ -749,6 +749,12 @@ class Function(object):
List of outputs on indices/keys from ``output_subset`` or all of them, List of outputs on indices/keys from ``output_subset`` or all of them,
if ``output_subset`` is not passed. if ``output_subset`` is not passed.
""" """
def restore_defaults():
for i, (required, refeed, value) in enumerate(self.defaults):
if refeed:
if isinstance(value, gof.Container):
value = value.storage[0]
self[i] = value
profile = self.profile profile = self.profile
t0 = time.time() t0 = time.time()
...@@ -853,14 +859,17 @@ class Function(object): ...@@ -853,14 +859,17 @@ class Function(object):
if not self.trust_input: if not self.trust_input:
for c in self.input_storage: for c in self.input_storage:
if c.required and not c.provided: if c.required and not c.provided:
restore_defaults()
raise TypeError("Missing required input: %s" % raise TypeError("Missing required input: %s" %
getattr(self.inv_finder[c], 'variable', getattr(self.inv_finder[c], 'variable',
self.inv_finder[c])) self.inv_finder[c]))
if c.provided > 1: if c.provided > 1:
restore_defaults()
raise TypeError("Multiple values for input: %s" % raise TypeError("Multiple values for input: %s" %
getattr(self.inv_finder[c], 'variable', getattr(self.inv_finder[c], 'variable',
self.inv_finder[c])) self.inv_finder[c]))
if c.implicit and c.provided > 0: if c.implicit and c.provided > 0:
restore_defaults()
raise TypeError( raise TypeError(
'Tried to provide value for implicit input: %s' 'Tried to provide value for implicit input: %s'
% getattr(self.inv_finder[c], 'variable', % getattr(self.inv_finder[c], 'variable',
...@@ -925,11 +934,7 @@ class Function(object): ...@@ -925,11 +934,7 @@ class Function(object):
outputs = outputs[:self.n_returned_outputs] outputs = outputs[:self.n_returned_outputs]
# Put default values back in the storage # Put default values back in the storage
for i, (required, refeed, value) in enumerate(self.defaults): restore_defaults()
if refeed:
if isinstance(value, gof.Container):
value = value.storage[0]
self[i] = value
# #
# NOTE: This logic needs to be replicated in # NOTE: This logic needs to be replicated in
# scan. # scan.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论