Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Added types to operator and pin specifications #1462

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/ansys/dpf/core/operator_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
The OperatorSpecification Provides a documentation for each Operator
"""

from __future__ import annotations
import abc
from typing import Union
from ansys.dpf.core import server as server_module
from ansys.dpf.gate import (
operator_specification_capi,
Expand Down Expand Up @@ -58,7 +60,7 @@ class PinSpecification:
name_derived_class = str

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

@property
def type_names(self):
def type_names(self) -> list[str]:
"""
Returns
-------
Expand Down Expand Up @@ -103,7 +105,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 +172,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 +191,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 +233,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,9 +274,9 @@ def __str__(self):
return "Description:\n" + str(self.description) + "\nProperties:\n" + str(self.properties)

@property
def properties(self):
"""Returns some additional properties of the Operator, like the category, the exposure,
the scripting and user names and the plugin
def properties(self) -> dict:
"""some additional properties of the Operator, like the category, the exposure,
the scripting and user names, and the plugin

Examples
--------
Expand Down Expand Up @@ -498,11 +500,11 @@ 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,
plugin: Union[str, None] = None,
license: str = None,
spec=None,
**kwargs,
Expand Down
Loading