From dd01328e5bdf6bb87bf1aeffd034252d033e5c71 Mon Sep 17 00:00:00 2001 From: Jan Vesely Date: Sun, 27 Mar 2022 22:30:55 -0400 Subject: [PATCH] fixup output port spec parsing --- .../core/components/ports/outputport.py | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/psyneulink/core/components/ports/outputport.py b/psyneulink/core/components/ports/outputport.py index 0094a92e571..5c2be3a09bc 100644 --- a/psyneulink/core/components/ports/outputport.py +++ b/psyneulink/core/components/ports/outputport.py @@ -674,10 +674,7 @@ 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] @@ -685,19 +682,14 @@ def parse_variable_spec(spec): # 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}.")