提交 d732dd05 authored 作者: james@X40's avatar james@X40

typos in compile.module

上级 c104defb
...@@ -377,6 +377,8 @@ class Method(Component): ...@@ -377,6 +377,8 @@ class Method(Component):
self.mode = mode self.mode = mode
def bind(self, parent, name, dup_ok=True): def bind(self, parent, name, dup_ok=True):
"""Implement`Component.bind`"""
rval = super(Method, self).bind(parent, name, dup_ok=dup_ok) rval = super(Method, self).bind(parent, name, dup_ok=dup_ok)
rval.resolve_all() rval.resolve_all()
return rval return rval
...@@ -384,7 +386,7 @@ class Method(Component): ...@@ -384,7 +386,7 @@ class Method(Component):
def resolve(self, name): def resolve(self, name):
"""Return the Result corresponding to a given name """Return the Result corresponding to a given name
:param name: the name of a Result in the Module instance containing this Method :param name: the name of a Result in the Module to which this Method is bound
:type name: str :type name: str
:rtype: `Result` :rtype: `Result`
...@@ -399,7 +401,7 @@ class Method(Component): ...@@ -399,7 +401,7 @@ class Method(Component):
def resolve_all(self): def resolve_all(self):
"""Convert all inputs, outputs, and updates specified as strings to Results. """Convert all inputs, outputs, and updates specified as strings to Results.
This works by searching the containing Module for Result attributes by these names. This works by searching the attribute list of the Module to which this Method is bound.
""" """
def resolve_result(x, passthrough=(gof.Result)): def resolve_result(x, passthrough=(gof.Result)):
if isinstance(x, passthrough): if isinstance(x, passthrough):
...@@ -418,10 +420,10 @@ class Method(Component): ...@@ -418,10 +420,10 @@ class Method(Component):
passthrough=(gof.Result, io.In)) for input in inputs] passthrough=(gof.Result, io.In)) for input in inputs]
def resolve_outputs(): def resolve_outputs():
if isinstance(self.outputs, (io.Out, gof.Result, str, None)): if isinstance(self.outputs, (io.Out, gof.Result, str, type(None))):
output = self.outputs output = self.outputs
self.outputs = resolve_result(output, self.outputs = resolve_result(output,
passthrough=(gof.Result, io.Out, None)) passthrough=(gof.Result, io.Out, type(None)))
else: else:
outputs = list(self.outputs) outputs = list(self.outputs)
self.outputs = [resolve_result(output, self.outputs = [resolve_result(output,
...@@ -1046,28 +1048,31 @@ class Module(ComponentDict): ...@@ -1046,28 +1048,31 @@ class Module(ComponentDict):
self.__set_name__(value) self.__set_name__(value)
return return
def identify_member(v): def unpack_member_and_external(v):
if isinstance(v, (Member, External)): if isinstance(v, (Member, External)):
print >> sys.stderr, ("WARNING: assignment of Member or External "
"objects (either directly or indirectly) to Module "
"is deprecated. Just use Result.")
return v.r return v.r
elif isinstance(v, (gof.Result,Method,Module)): elif isinstance(v, (gof.Result,Method,Module)):
return v return v
elif isinstance(v,(int,bool)): elif isinstance(v,(int,bool)):
return v return v
elif isinstance(v, (list)): elif isinstance(v, (list)):
return map(identify_member,v) return map(unpack_member_and_external,v)
elif isinstance(v, (tuple)): elif isinstance(v, (tuple)):
return tuple(map(identify_member,v)) return tuple(map(unpack_member_and_external,v))
elif isinstance(v,dict): elif isinstance(v,dict):
v_copy = dict() v_copy = dict()
for k,vv in v.iteritems(): for k,vv in v.iteritems():
v_copy[k]=identify_member(vv) v_copy[k]=unpack_member_and_external(vv)
return v return v
else: else:
# raise NotImplementedError # raise NotImplementedError
# print "WARNING: unknow:",v # print "WARNING: unknow:",v
return v return v
value=identify_member(value) value=unpack_member_and_external(value)
if not hasattr(self,"local_attr"): if not hasattr(self,"local_attr"):
self.__dict__["local_attr"]={} self.__dict__["local_attr"]={}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论