Skip to content

Commit

Permalink
Fix connecting Any as inpt (#1991)
Browse files Browse the repository at this point in the history
* Fix Any flagged as ambiguous inpt in Operator._find_outputs_corresponding_pins.

* Add test for reported failure

* Better fix
  • Loading branch information
PProfizi authored Jan 7, 2025
1 parent ff8e662 commit 7ba086b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ansys/dpf/core/dpf_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7ba086b

Please sign in to comment.