Skip to content

Commit 5370c52

Browse files
BClappePipKat
andauthored
refactor: Added types to operator and pin specifications (#1462)
* refactor: Added types to operator and pin specifications * Update src/ansys/dpf/core/operator_specification.py Co-authored-by: Kathy Pippert <[email protected]> * types: removed brackets in type annotations * types: added annotations from future --------- Co-authored-by: Kathy Pippert <[email protected]>
1 parent 3f07e6c commit 5370c52

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/ansys/dpf/core/operator_specification.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
The OperatorSpecification Provides a documentation for each Operator
77
"""
88

9+
from __future__ import annotations
910
import abc
11+
from typing import Union
1012
from ansys.dpf.core import server as server_module
1113
from ansys.dpf.gate import (
1214
operator_specification_capi,
@@ -58,7 +60,7 @@ class PinSpecification:
5860
name_derived_class = str
5961

6062
def __init__(
61-
self, name, type_names, document="", optional=False, ellipsis=False, name_derived_class=""
63+
self, name: str, type_names: list, document="", optional=False, ellipsis=False, name_derived_class=""
6264
):
6365
self.name = name
6466
self.type_names = type_names
@@ -68,7 +70,7 @@ def __init__(
6870
self.name_derived_class = name_derived_class
6971

7072
@property
71-
def type_names(self):
73+
def type_names(self) -> list[str]:
7274
"""
7375
Returns
7476
-------
@@ -103,7 +105,7 @@ def type_names(self, val):
103105
self._type_names = val
104106

105107
@staticmethod
106-
def _get_copy(other, changed_types):
108+
def _get_copy(other, changed_types) -> PinSpecification:
107109
return PinSpecification(
108110
other.name,
109111
changed_types,
@@ -170,7 +172,7 @@ class ConfigOptionSpec:
170172
default_value_str: str
171173
document: str
172174

173-
def __init__(self, name, type_names, default_value_str, document):
175+
def __init__(self, name: str, type_names: list, default_value_str: str, document: str):
174176
self.name = name
175177
self.type_names = type_names
176178
self.default_value_str = default_value_str
@@ -189,17 +191,17 @@ def __repr__(self):
189191
class SpecificationBase:
190192
@property
191193
@abc.abstractmethod
192-
def description(self):
194+
def description(self) -> Union[str, None]:
193195
pass
194196

195197
@property
196198
@abc.abstractmethod
197-
def inputs(self):
199+
def inputs(self) -> dict:
198200
pass
199201

200202
@property
201203
@abc.abstractmethod
202-
def outputs(self):
204+
def outputs(self) -> dict:
203205
pass
204206

205207

@@ -231,7 +233,7 @@ class Specification(SpecificationBase):
231233
'result file path container, used if no streams are set'
232234
"""
233235

234-
def __init__(self, operator_name=None, specification=None, server=None):
236+
def __init__(self, operator_name: Union[str, None]=None, specification: Union[Specification, None]=None, server: Union[server_module.BaseServer, None]=None):
235237
# step 1: get server
236238
self._server = server_module.get_or_create_server(server)
237239

@@ -272,9 +274,9 @@ def __str__(self):
272274
return "Description:\n" + str(self.description) + "\nProperties:\n" + str(self.properties)
273275

274276
@property
275-
def properties(self):
276-
"""Returns some additional properties of the Operator, like the category, the exposure,
277-
the scripting and user names and the plugin
277+
def properties(self) -> dict:
278+
"""some additional properties of the Operator, like the category, the exposure,
279+
the scripting and user names, and the plugin
278280
279281
Examples
280282
--------
@@ -498,11 +500,11 @@ class SpecificationProperties:
498500

499501
def __init__(
500502
self,
501-
user_name: str = None,
502-
category: str = None,
503-
scripting_name: str = None,
503+
user_name: Union[str, None] = None,
504+
category: Union[str, None] = None,
505+
scripting_name: Union[str, None] = None,
504506
exposure: Exposures = Exposures.public,
505-
plugin: str = None,
507+
plugin: Union[str, None] = None,
506508
license: str = None,
507509
spec=None,
508510
**kwargs,

0 commit comments

Comments
 (0)