@@ -2422,18 +2422,18 @@ def interconnect(
24222422 elif not found_system :
24232423 raise ValueError ("could not find signal %s" % sname )
24242424 else :
2425- # TODO: refactor code to remove duplication
24262425 if isinstance (connection , list ):
24272426 # Passed a list => create input map
24282427 dprint (f" detected input list" )
2429- new_inplist . append ([])
2428+ signal_list = []
24302429 for spec in connection :
24312430 isys , indices , gain = _parse_spec (syslist , spec , 'input' )
24322431 for isig in indices :
2433- new_inplist [- 1 ].append ((isys , isig , gain ))
2434- dprint (f" adding input { (isys , isig , gain )} " )
2432+ signal_list .append ((isys , isig , gain ))
2433+ dprint (f" adding input { (isys , isig , gain )} to list" )
2434+ new_inplist .append (signal_list )
24352435 else :
2436- # Passed a single single => single input
2436+ # Passed a single signal name => add individual input(s)
24372437 isys , indices , gain = _parse_spec (syslist , connection , 'input' )
24382438 for isig in indices :
24392439 new_inplist .append ((isys , isig , gain ))
@@ -2503,39 +2503,15 @@ def interconnect(
25032503 elif not found_system :
25042504 raise ValueError ("could not find signal %s" % sname )
25052505 else :
2506- # TODO: refactor code to remove duplication
2507- if isinstance (connection , list ):
2508- # Passed a list => create input map
2509- dprint (f" detected output list" )
2510- new_outlist .append ([])
2511- for spec in connection :
2512- try :
2513- # First trying looking in the output signals
2514- osys , indices , gain = _parse_spec (
2515- syslist , spec , 'output' )
2516- for osig in indices :
2517- dprint (f" adding output { (osys , osig , gain )} " )
2518- new_outlist [- 1 ].append ((osys , osig , gain ))
2519- except ValueError :
2520- # If not, see if we can find it in inputs
2521- isys , indices , gain = _parse_spec (
2522- syslist , spec , 'input or output' ,
2523- dictname = 'input_index' )
2524- for isig in indices :
2525- # Use string form to allow searching input list
2526- dprint (f" adding input { (isys , isig , gain )} " )
2527- new_outlist [- 1 ].append (
2528- (syslist [isys ].name ,
2529- syslist [isys ].input_labels [isig ], gain ))
2530- else :
2531- spec = connection
2506+ # Utility function to find named output or input signal
2507+ def _find_output_or_input_signal (spec ):
2508+ signal_list = []
25322509 try :
25332510 # First trying looking in the output signals
2534- osys , indices , gain = _parse_spec (
2535- syslist , spec , 'output' )
2511+ osys , indices , gain = _parse_spec (syslist , spec , 'output' )
25362512 for osig in indices :
2537- dprint (f" adding output { (osys , osig , gain )} " )
2538- new_outlist .append ((osys , osig , gain ))
2513+ dprint (f" adding output { (osys , osig , gain )} " )
2514+ signal_list .append ((osys , osig , gain ))
25392515 except ValueError :
25402516 # If not, see if we can find it in inputs
25412517 isys , indices , gain = _parse_spec (
@@ -2544,9 +2520,21 @@ def interconnect(
25442520 for isig in indices :
25452521 # Use string form to allow searching input list
25462522 dprint (f" adding input { (isys , isig , gain )} " )
2547- new_outlist .append (
2523+ signal_list .append (
25482524 (syslist [isys ].name ,
25492525 syslist [isys ].input_labels [isig ], gain ))
2526+ return signal_list
2527+
2528+ if isinstance (connection , list ):
2529+ # Passed a list => create input map
2530+ dprint (f" detected output list" )
2531+ signal_list = []
2532+ for spec in connection :
2533+ signal_list += _find_output_or_input_signal (spec )
2534+ new_outlist .append (signal_list )
2535+ else :
2536+ new_outlist += _find_output_or_input_signal (connection )
2537+
25502538 outlist , outputs = new_outlist , new_outputs
25512539 dprint (f" { outlist = } \n { outputs = } " )
25522540
0 commit comments