Skip to content

Commit 6dc6db5

Browse files
moe-adpyansys-ci-botPProfizi
authored
feat(typing): improve type hinting of Input/Output classes and operators subpackage (#2732)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: PProfizi <[email protected]>
1 parent d5130b3 commit 6dc6db5

File tree

786 files changed

+21086
-10143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

786 files changed

+21086
-10143
lines changed

src/ansys/dpf/core/inputs.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424

2525
from enum import Enum
2626
from textwrap import wrap
27+
from typing import Generic, TypeVar
2728
import warnings
2829
import weakref
2930

3031
from ansys.dpf import core
3132
from ansys.dpf.core.mapping_types import map_types_to_python
3233
from ansys.dpf.core.outputs import Output, _Outputs
3334

35+
T = TypeVar("T")
3436

35-
class Input:
37+
38+
class Input(Generic[T]):
3639
"""
3740
Intermediate class internally instantiated by the :class:`ansys.dpf.core.dpf_operator.Operator`.
3841
@@ -70,16 +73,8 @@ def __init__(self, spec, pin, operator, count_ellipsis=-1):
7073
self.name += str(self._count_ellipsis + 1)
7174
self._update_doc_str(docstr, self.name)
7275

73-
def connect(self, inpt):
74-
"""Connect any input (entity or operator output) to a specified input pin of this operator.
75-
76-
Parameters
77-
----------
78-
inpt : str, int, double, Field, FieldsContainer, Scoping, DataSources, MeshedRegion, Enum,
79-
Output, Outputs, Operator, os.PathLike
80-
Input of the operator.
81-
82-
"""
76+
def connect(self, inpt: T):
77+
"""Connect any input (entity or operator output) to a specified input pin of this operator."""
8378
from pathlib import Path
8479

8580
# always convert ranges to lists
@@ -173,7 +168,7 @@ def connect(self, inpt):
173168

174169
self.__inc_if_ellipsis()
175170

176-
def __call__(self, inpt):
171+
def __call__(self, inpt: T):
177172
"""Allow instances to be called like a function."""
178173
self.connect(inpt)
179174

@@ -241,13 +236,6 @@ def connect(self, inpt):
241236
242237
.. deprecated::
243238
Deprecated in favor of explicit output-to-input connections.
244-
245-
Parameters
246-
----------
247-
inpt : str, int, double, bool, list[int], list[float], Field, FieldsContainer, Scoping, Enum,
248-
ScopingsContainer, MeshedRegion, MeshesContainer, DataSources, CyclicSupport, Outputs, os.PathLike # noqa: E501
249-
Input of the operator.
250-
251239
"""
252240
warnings.warn(
253241
message="Use explicit output-to-input connections.", category=DeprecationWarning

src/ansys/dpf/core/operators/averaging/elemental_difference.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from __future__ import annotations
8+
from typing import TYPE_CHECKING
89

910
from warnings import warn
1011
from ansys.dpf.core.dpf_operator import Operator
@@ -14,6 +15,12 @@
1415
from ansys.dpf.core.config import Config
1516
from ansys.dpf.core.server_types import AnyServerType
1617

18+
if TYPE_CHECKING:
19+
from ansys.dpf.core.field import Field
20+
from ansys.dpf.core.fields_container import FieldsContainer
21+
from ansys.dpf.core.meshed_region import MeshedRegion
22+
from ansys.dpf.core.scoping import Scoping
23+
1724

1825
class elemental_difference(Operator):
1926
r"""Transforms an Elemental Nodal or Nodal field into an Elemental field.
@@ -199,19 +206,25 @@ class InputsElementalDifference(_Inputs):
199206

200207
def __init__(self, op: Operator):
201208
super().__init__(elemental_difference._spec().inputs, op)
202-
self._field = Input(elemental_difference._spec().input_pin(0), 0, op, -1)
209+
self._field: Input[Field | FieldsContainer] = Input(
210+
elemental_difference._spec().input_pin(0), 0, op, -1
211+
)
203212
self._inputs.append(self._field)
204-
self._mesh_scoping = Input(elemental_difference._spec().input_pin(1), 1, op, -1)
213+
self._mesh_scoping: Input[Scoping] = Input(
214+
elemental_difference._spec().input_pin(1), 1, op, -1
215+
)
205216
self._inputs.append(self._mesh_scoping)
206-
self._mesh = Input(elemental_difference._spec().input_pin(7), 7, op, -1)
217+
self._mesh: Input[MeshedRegion] = Input(
218+
elemental_difference._spec().input_pin(7), 7, op, -1
219+
)
207220
self._inputs.append(self._mesh)
208-
self._through_layers = Input(
221+
self._through_layers: Input[bool] = Input(
209222
elemental_difference._spec().input_pin(10), 10, op, -1
210223
)
211224
self._inputs.append(self._through_layers)
212225

213226
@property
214-
def field(self) -> Input:
227+
def field(self) -> Input[Field | FieldsContainer]:
215228
r"""Allows to connect field input to the operator.
216229
217230
field or fields container with only one field is expected
@@ -232,7 +245,7 @@ def field(self) -> Input:
232245
return self._field
233246

234247
@property
235-
def mesh_scoping(self) -> Input:
248+
def mesh_scoping(self) -> Input[Scoping]:
236249
r"""Allows to connect mesh_scoping input to the operator.
237250
238251
average only on these entities
@@ -253,7 +266,7 @@ def mesh_scoping(self) -> Input:
253266
return self._mesh_scoping
254267

255268
@property
256-
def mesh(self) -> Input:
269+
def mesh(self) -> Input[MeshedRegion]:
257270
r"""Allows to connect mesh input to the operator.
258271
259272
Returns
@@ -272,7 +285,7 @@ def mesh(self) -> Input:
272285
return self._mesh
273286

274287
@property
275-
def through_layers(self) -> Input:
288+
def through_layers(self) -> Input[bool]:
276289
r"""Allows to connect through_layers input to the operator.
277290
278291
The maximum elemental difference is taken through the different shell layers if true (default is false).
@@ -307,11 +320,13 @@ class OutputsElementalDifference(_Outputs):
307320

308321
def __init__(self, op: Operator):
309322
super().__init__(elemental_difference._spec().outputs, op)
310-
self._field = Output(elemental_difference._spec().output_pin(0), 0, op)
323+
self._field: Output[Field] = Output(
324+
elemental_difference._spec().output_pin(0), 0, op
325+
)
311326
self._outputs.append(self._field)
312327

313328
@property
314-
def field(self) -> Output:
329+
def field(self) -> Output[Field]:
315330
r"""Allows to get field output of the operator
316331
317332
Returns

src/ansys/dpf/core/operators/averaging/elemental_difference_fc.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from __future__ import annotations
8+
from typing import TYPE_CHECKING
89

910
from warnings import warn
1011
from ansys.dpf.core.dpf_operator import Operator
@@ -14,6 +15,13 @@
1415
from ansys.dpf.core.config import Config
1516
from ansys.dpf.core.server_types import AnyServerType
1617

18+
if TYPE_CHECKING:
19+
from ansys.dpf.core.fields_container import FieldsContainer
20+
from ansys.dpf.core.meshed_region import MeshedRegion
21+
from ansys.dpf.core.meshes_container import MeshesContainer
22+
from ansys.dpf.core.scoping import Scoping
23+
from ansys.dpf.core.scopings_container import ScopingsContainer
24+
1725

1826
class elemental_difference_fc(Operator):
1927
r"""Transforms an Elemental Nodal or Nodal field into an Elemental field.
@@ -205,21 +213,25 @@ class InputsElementalDifferenceFc(_Inputs):
205213

206214
def __init__(self, op: Operator):
207215
super().__init__(elemental_difference_fc._spec().inputs, op)
208-
self._fields_container = Input(
216+
self._fields_container: Input[FieldsContainer] = Input(
209217
elemental_difference_fc._spec().input_pin(0), 0, op, -1
210218
)
211219
self._inputs.append(self._fields_container)
212-
self._mesh = Input(elemental_difference_fc._spec().input_pin(1), 1, op, -1)
220+
self._mesh: Input[MeshedRegion | MeshesContainer] = Input(
221+
elemental_difference_fc._spec().input_pin(1), 1, op, -1
222+
)
213223
self._inputs.append(self._mesh)
214-
self._scoping = Input(elemental_difference_fc._spec().input_pin(3), 3, op, -1)
224+
self._scoping: Input[Scoping | ScopingsContainer] = Input(
225+
elemental_difference_fc._spec().input_pin(3), 3, op, -1
226+
)
215227
self._inputs.append(self._scoping)
216-
self._collapse_shell_layers = Input(
228+
self._collapse_shell_layers: Input[bool] = Input(
217229
elemental_difference_fc._spec().input_pin(10), 10, op, -1
218230
)
219231
self._inputs.append(self._collapse_shell_layers)
220232

221233
@property
222-
def fields_container(self) -> Input:
234+
def fields_container(self) -> Input[FieldsContainer]:
223235
r"""Allows to connect fields_container input to the operator.
224236
225237
Returns
@@ -238,7 +250,7 @@ def fields_container(self) -> Input:
238250
return self._fields_container
239251

240252
@property
241-
def mesh(self) -> Input:
253+
def mesh(self) -> Input[MeshedRegion | MeshesContainer]:
242254
r"""Allows to connect mesh input to the operator.
243255
244256
The mesh region in this pin is used to perform the averaging, used if there is no fields support.
@@ -259,7 +271,7 @@ def mesh(self) -> Input:
259271
return self._mesh
260272

261273
@property
262-
def scoping(self) -> Input:
274+
def scoping(self) -> Input[Scoping | ScopingsContainer]:
263275
r"""Allows to connect scoping input to the operator.
264276
265277
Average only on these elements. If it is scoping container, the label must correspond to the one of the fields container.
@@ -280,7 +292,7 @@ def scoping(self) -> Input:
280292
return self._scoping
281293

282294
@property
283-
def collapse_shell_layers(self) -> Input:
295+
def collapse_shell_layers(self) -> Input[bool]:
284296
r"""Allows to connect collapse_shell_layers input to the operator.
285297
286298
If true, the data across different shell layers is averaged as well (default is false).
@@ -315,13 +327,13 @@ class OutputsElementalDifferenceFc(_Outputs):
315327

316328
def __init__(self, op: Operator):
317329
super().__init__(elemental_difference_fc._spec().outputs, op)
318-
self._fields_container = Output(
330+
self._fields_container: Output[FieldsContainer] = Output(
319331
elemental_difference_fc._spec().output_pin(0), 0, op
320332
)
321333
self._outputs.append(self._fields_container)
322334

323335
@property
324-
def fields_container(self) -> Output:
336+
def fields_container(self) -> Output[FieldsContainer]:
325337
r"""Allows to get fields_container output of the operator
326338
327339
Returns

src/ansys/dpf/core/operators/averaging/elemental_fraction_fc.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from __future__ import annotations
8+
from typing import TYPE_CHECKING
89

910
from warnings import warn
1011
from ansys.dpf.core.dpf_operator import Operator
@@ -14,6 +15,11 @@
1415
from ansys.dpf.core.config import Config
1516
from ansys.dpf.core.server_types import AnyServerType
1617

18+
if TYPE_CHECKING:
19+
from ansys.dpf.core.fields_container import FieldsContainer
20+
from ansys.dpf.core.meshed_region import MeshedRegion
21+
from ansys.dpf.core.scoping import Scoping
22+
1723

1824
class elemental_fraction_fc(Operator):
1925
r"""Transforms Elemental Nodal fields into Elemental fields. Each elemental
@@ -213,23 +219,29 @@ class InputsElementalFractionFc(_Inputs):
213219

214220
def __init__(self, op: Operator):
215221
super().__init__(elemental_fraction_fc._spec().inputs, op)
216-
self._fields_container = Input(
222+
self._fields_container: Input[FieldsContainer] = Input(
217223
elemental_fraction_fc._spec().input_pin(0), 0, op, -1
218224
)
219225
self._inputs.append(self._fields_container)
220-
self._mesh = Input(elemental_fraction_fc._spec().input_pin(1), 1, op, -1)
226+
self._mesh: Input[MeshedRegion] = Input(
227+
elemental_fraction_fc._spec().input_pin(1), 1, op, -1
228+
)
221229
self._inputs.append(self._mesh)
222-
self._scoping = Input(elemental_fraction_fc._spec().input_pin(3), 3, op, -1)
230+
self._scoping: Input[Scoping] = Input(
231+
elemental_fraction_fc._spec().input_pin(3), 3, op, -1
232+
)
223233
self._inputs.append(self._scoping)
224-
self._denominator = Input(elemental_fraction_fc._spec().input_pin(6), 6, op, -1)
234+
self._denominator: Input[FieldsContainer] = Input(
235+
elemental_fraction_fc._spec().input_pin(6), 6, op, -1
236+
)
225237
self._inputs.append(self._denominator)
226-
self._collapse_shell_layers = Input(
238+
self._collapse_shell_layers: Input[bool] = Input(
227239
elemental_fraction_fc._spec().input_pin(10), 10, op, -1
228240
)
229241
self._inputs.append(self._collapse_shell_layers)
230242

231243
@property
232-
def fields_container(self) -> Input:
244+
def fields_container(self) -> Input[FieldsContainer]:
233245
r"""Allows to connect fields_container input to the operator.
234246
235247
Returns
@@ -248,7 +260,7 @@ def fields_container(self) -> Input:
248260
return self._fields_container
249261

250262
@property
251-
def mesh(self) -> Input:
263+
def mesh(self) -> Input[MeshedRegion]:
252264
r"""Allows to connect mesh input to the operator.
253265
254266
The mesh region in this pin is used to perform the averaging. It is used if there is no fields support.
@@ -269,7 +281,7 @@ def mesh(self) -> Input:
269281
return self._mesh
270282

271283
@property
272-
def scoping(self) -> Input:
284+
def scoping(self) -> Input[Scoping]:
273285
r"""Allows to connect scoping input to the operator.
274286
275287
Average only on these elements. If it is a scoping container, the label must correspond to the one of the fields containers.
@@ -290,7 +302,7 @@ def scoping(self) -> Input:
290302
return self._scoping
291303

292304
@property
293-
def denominator(self) -> Input:
305+
def denominator(self) -> Input[FieldsContainer]:
294306
r"""Allows to connect denominator input to the operator.
295307
296308
If a fields container is set in this pin, it is used as the denominator of the fraction instead of entity_average_fc.
@@ -311,7 +323,7 @@ def denominator(self) -> Input:
311323
return self._denominator
312324

313325
@property
314-
def collapse_shell_layers(self) -> Input:
326+
def collapse_shell_layers(self) -> Input[bool]:
315327
r"""Allows to connect collapse_shell_layers input to the operator.
316328
317329
If true, the data across different shell layers is averaged as well (default is false).
@@ -346,13 +358,13 @@ class OutputsElementalFractionFc(_Outputs):
346358

347359
def __init__(self, op: Operator):
348360
super().__init__(elemental_fraction_fc._spec().outputs, op)
349-
self._fields_container = Output(
361+
self._fields_container: Output[FieldsContainer] = Output(
350362
elemental_fraction_fc._spec().output_pin(0), 0, op
351363
)
352364
self._outputs.append(self._fields_container)
353365

354366
@property
355-
def fields_container(self) -> Output:
367+
def fields_container(self) -> Output[FieldsContainer]:
356368
r"""Allows to get fields_container output of the operator
357369
358370
Returns

0 commit comments

Comments
 (0)