diff --git a/src/ansys/dpf/core/inputs.py b/src/ansys/dpf/core/inputs.py index 16fda8534f..98be8801d3 100644 --- a/src/ansys/dpf/core/inputs.py +++ b/src/ansys/dpf/core/inputs.py @@ -23,6 +23,7 @@ """Inputs.""" from textwrap import wrap +import warnings import weakref from ansys.dpf import core @@ -112,7 +113,7 @@ def connect(self, inpt): self._python_expected_types, inpt, self._pin, corresponding_pins ) if len(corresponding_pins) > 1: - err_str = "Pin connection is ambiguous, specify the pin with:\n" + err_str = "Pin connection is ambiguous, specify the input to connect to with:\n" for pin in corresponding_pins: err_str += ( " - operator.inputs." @@ -121,7 +122,9 @@ def connect(self, inpt): + inpt._dict_outputs[pin[1]].name + ")" ) - raise ValueError(err_str) + err_str += "Connecting to first input in the list.\n" + warnings.warn(message=err_str) + corresponding_pins = [corresponding_pins[0]] if len(corresponding_pins) == 0: err_str = ( @@ -218,6 +221,9 @@ def connect(self, inpt): Searches for the input type corresponding to the output. + .. deprecated:: + Deprecated in favor of explicit output-to-input connections. + Parameters ---------- inpt : str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping, @@ -225,6 +231,10 @@ def connect(self, inpt): Input of the operator. """ + warnings.warn( + message="Use explicit output-to-input connections.", category=DeprecationWarning + ) + from pathlib import Path corresponding_pins = [] @@ -250,12 +260,14 @@ def connect(self, inpt): corresponding_pins, ) if len(corresponding_pins) > 1: - err_str = "Pin connection is ambiguous, specify the pin with:\n" + err_str = "Pin connection is ambiguous, specify the input to connect to with:\n" for pin in corresponding_pins: if isinstance(pin, tuple): pin = pin[0] err_str += " - operator.inputs." + self._dict_inputs[pin].name + "(input)\n" - raise ValueError(err_str) + err_str += "Connecting to first input in the list.\n" + warnings.warn(message=err_str) + corresponding_pins = [corresponding_pins[0]] if len(corresponding_pins) == 0: err_str = "The input should have one of the expected types:\n" diff --git a/tests/test_operator.py b/tests/test_operator.py index bee55564dd..fdef9abdd1 100644 --- a/tests/test_operator.py +++ b/tests/test_operator.py @@ -556,7 +556,11 @@ def test_inputs_outputs_scopings_container(allkindofcomplexity): assert scop.location == dpf.core.locations.elemental stress = model.results.stress() - stress.inputs.connect(op.outputs) + with ( + # pytest.warns(match="Pin connection is ambiguous"), + pytest.warns(DeprecationWarning, match="Use explicit"), + ): + stress.inputs.connect(op.outputs) fc = stress.outputs.fields_container() assert fc.labels == ["elshape", "time"] assert len(fc) == 4 @@ -589,8 +593,17 @@ def test_inputs_outputs_meshes_container(allkindofcomplexity): sc = opsc.outputs.mesh_scoping() stress = model.results.stress() - stress.inputs.connect(op.outputs) - stress.inputs.connect(opsc.outputs) + with ( + # pytest.warns(match="Pin connection is ambiguous"), + pytest.warns(DeprecationWarning, match="Use explicit"), + ): + stress.inputs.connect(op.outputs) + + with ( + # pytest.warns(match="Pin connection is ambiguous"), + pytest.warns(DeprecationWarning, match="Use explicit"), + ): + stress.inputs.connect(opsc.outputs) fc = stress.outputs.fields_container() assert fc.labels == ["body", "elshape", "time"] assert len(fc) == 4