From 7ba086b9eb06b1be455478880a01bdd3c737fe9a Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:16:47 +0100 Subject: [PATCH] Fix connecting Any as inpt (#1991) * Fix Any flagged as ambiguous inpt in Operator._find_outputs_corresponding_pins. * Add test for reported failure * Better fix --- src/ansys/dpf/core/dpf_operator.py | 10 +++++++--- tests/test_operator.py | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ansys/dpf/core/dpf_operator.py b/src/ansys/dpf/core/dpf_operator.py index 62578d3d0d..ed5f69182a 100644 --- a/src/ansys/dpf/core/dpf_operator.py +++ b/src/ansys/dpf/core/dpf_operator.py @@ -829,8 +829,10 @@ def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_ if python_name == "B": python_name = "bool" + # Type match if type(inpt).__name__ == python_name: corresponding_pins.append(pin) + # if the inpt has multiple potential outputs, find which ones can match elif isinstance(inpt, (_Outputs, Operator, Result)): if isinstance(inpt, Operator): output_pin_available = inpt.outputs._get_given_output([python_name]) @@ -840,12 +842,14 @@ def _find_outputs_corresponding_pins(self, type_names, inpt, pin, corresponding_ output_pin_available = inpt._get_given_output([python_name]) for outputpin in output_pin_available: corresponding_pins.append((pin, outputpin)) + # If any output type matches python_name elif isinstance(inpt, Output): - for inpttype in inpt._python_expected_types: - if inpttype == python_name: - corresponding_pins.append(pin) if python_name == "Any": corresponding_pins.append(pin) + else: + for inpttype in inpt._python_expected_types: + if inpttype == python_name: + corresponding_pins.append(pin) elif python_name == "Any": corresponding_pins.append(pin) diff --git a/tests/test_operator.py b/tests/test_operator.py index 380c5edbd7..124e988b50 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -1496,3 +1496,9 @@ def test_operator_id(server_type): assert op.id not in ids ids.add(op.id) + + +def test_operator_find_outputs_corresponding_pins_any(server_type): + f1 = ops.utility.forward() + f2 = ops.utility.forward() + f2.inputs.any.connect(f1.outputs.any)