Skip to content

Commit

Permalink
refactor: Added types to operator and pin specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
BClappe committed Mar 8, 2024
1 parent a2d17c3 commit 9dba4d2
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/ansys/dpf/core/operator_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import abc
from typing import Any, Union
from ansys.dpf.core import server as server_module
from ansys.dpf.gate import (
operator_specification_capi,
Expand Down Expand Up @@ -51,14 +52,14 @@ class PinSpecification:
"""

name: str
_type_names: list
_type_names: list[Any]
document: str
optional: bool
ellipsis: bool
name_derived_class = str

def __init__(
self, name, type_names, document="", optional=False, ellipsis=False, name_derived_class=""
self, name: str, type_names: list[Any], document="", optional=False, ellipsis=False, name_derived_class=""
):
self.name = name
self.type_names = type_names
Expand All @@ -68,7 +69,7 @@ def __init__(
self.name_derived_class = name_derived_class

@property
def type_names(self):
def type_names(self) -> list[Any]:
"""
Returns
-------
Expand Down Expand Up @@ -103,7 +104,7 @@ def type_names(self, val):
self._type_names = val

@staticmethod
def _get_copy(other, changed_types):
def _get_copy(other, changed_types) -> "PinSpecification":
return PinSpecification(
other.name,
changed_types,
Expand Down Expand Up @@ -170,7 +171,7 @@ class ConfigOptionSpec:
default_value_str: str
document: str

def __init__(self, name, type_names, default_value_str, document):
def __init__(self, name: str, type_names: list, default_value_str: str, document: str):
self.name = name
self.type_names = type_names
self.default_value_str = default_value_str
Expand All @@ -189,17 +190,17 @@ def __repr__(self):
class SpecificationBase:
@property
@abc.abstractmethod
def description(self):
def description(self) -> Union[str, None]:
pass

@property
@abc.abstractmethod
def inputs(self):
def inputs(self) -> dict:
pass

@property
@abc.abstractmethod
def outputs(self):
def outputs(self) -> dict:
pass


Expand Down Expand Up @@ -231,7 +232,7 @@ class Specification(SpecificationBase):
'result file path container, used if no streams are set'
"""

def __init__(self, operator_name=None, specification=None, server=None):
def __init__(self, operator_name: Union[str, None]=None, specification: Union["Specification", None]=None, server: Union[server_module.BaseServer, None]=None):
# step 1: get server
self._server = server_module.get_or_create_server(server)

Expand Down Expand Up @@ -272,7 +273,7 @@ def __str__(self):
return "Description:\n" + str(self.description) + "\nProperties:\n" + str(self.properties)

@property
def properties(self):
def properties(self) -> dict:
"""Returns some additional properties of the Operator, like the category, the exposure,
the scripting and user names and the plugin
Expand Down Expand Up @@ -498,12 +499,12 @@ class SpecificationProperties:

def __init__(
self,
user_name: str = None,
category: str = None,
scripting_name: str = None,
user_name: Union[str, None] = None,
category: Union[str, None] = None,
scripting_name: Union[str, None] = None,
exposure: Exposures = Exposures.public,
plugin: str = None,
license: str = None,
plugin: Union[str, None] = None,
license: Union[str, None] = None,
spec=None,
**kwargs,
):
Expand Down

0 comments on commit 9dba4d2

Please sign in to comment.