Skip to content

Commit

Permalink
fixup output port spec parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jvesely committed Mar 28, 2022
1 parent 05b7e6f commit dd01328
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions psyneulink/core/components/ports/outputport.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,30 +674,22 @@ def parse_variable_spec(spec):
return spec
elif isinstance(spec, tuple):
# Tuple indexing item of owner's attribute (e.g.,: OWNER_VALUE, int))
try:
owner_param_name = output_port_spec_to_parameter_name[spec[0]]
except KeyError:
owner_param_name = spec[0]
owner_param_name = output_port_spec_to_parameter_name.get(spec[0], spec[0])

try:
index = spec[1]() if callable(spec[1]) else spec[1]

# context is None during initialization, and we don't want to
# incur the cost of .get during execution
if context is None:
return getattr(owner.parameters, owner_param_name).get(context)[index]
else:
return getattr(owner.parameters, owner_param_name)._get(context)[index]
except TypeError:
if context is None:
if getattr(owner.parameters, owner_param_name).get(context) is None:
return None
elif getattr(owner.parameters, owner_param_name)._get(context) is None:
return None
val = getattr(owner.parameters, owner_param_name).get(context)
else:
# raise OutputPortError("Can't parse variable ({}) for {} of {}".
# format(spec, output_port_name or OutputPort.__name__, owner.name))
raise Exception
val = getattr(owner.parameters, owner_param_name)._get(context)

if hasattr(val, '_get_by_time_scale'):
return val._get_by_time_scale(index)

return val if val is None else val[index]
except:
raise OutputPortError(f"Can't parse variable ({spec}) for "
f"{output_port_name or OutputPort.__name__} of {owner.name}.")
Expand Down

0 comments on commit dd01328

Please sign in to comment.