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

Replace Union with Optional. #263

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/ansys/optislang/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def __init__(self): # pragma: no cover

@property
@abstractmethod
def project(self) -> Union[Project, None]:
def project(self) -> Optional[Project]:
"""Instance of the ``Project`` class.

Returns
-------
Union[Project, None]
Optional[Project]
Loaded project. If no project is loaded, ``None`` is returned.
"""
pass
Expand Down
14 changes: 7 additions & 7 deletions src/ansys/optislang/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from enum import Enum
from pathlib import Path
import time
from typing import Union
from typing import Optional, Union

from ansys.optislang.core.utils import enum_from_str

Expand Down Expand Up @@ -94,12 +94,12 @@ def filename(self) -> str:
return self.path.name

@property
def last_modified_seconds(self) -> Union[float, None]:
def last_modified_seconds(self) -> Optional[float]:
"""Last modified time as a timestamp.

Returns
-------
Union[float, None]
Optional[float]
Last modified time in seconds since the Epoch, `None` if file doesn't exist.
"""
if self.exists:
Expand All @@ -108,12 +108,12 @@ def last_modified_seconds(self) -> Union[float, None]:
return None

@property
def last_modified_str(self) -> Union[str, None]:
def last_modified_str(self) -> Optional[str]:
"""Last modified time as a datetime.

Returns
-------
Union[str, None]
Optional[str]
Last modified time as string, `None` if file doesn't exist.
"""
if self.exists:
Expand All @@ -133,12 +133,12 @@ def path(self) -> Path:
return self.__path

@property
def size(self) -> Union[int, None]:
def size(self) -> Optional[int]:
"""File size in bytes.

Returns
-------
Union[int, None]
Optional[int]
File size in bytes, `None` in file doesn't exist.
"""
if self.exists:
Expand Down
20 changes: 10 additions & 10 deletions src/ansys/optislang/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,18 +1057,18 @@ def __init__(self): # pragma: no cover
def create_node(
self,
type_: NodeType,
name: Union[str, None] = None,
design_flow: Union[DesignFlow, None] = None,
name: Optional[str] = None,
design_flow: Optional[DesignFlow] = None,
) -> Node: # pragma: no cover
"""Create a new node in current system in active project.

Parameters
----------
type_ : NodeType
Type of created node.
name : Union[str, None], optional
name : Optional[str], optional
Name of created node, by default None.
design_flow : Union[DesignFlow, None], optional
design_flow : Optional[DesignFlow], optional
Design flow, by default None.

Returns
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def delete_children_nodes(self) -> None: # pragma: no cover
@abstractmethod
def find_node_by_uid(
self, uid: str, search_depth: int = 1
) -> Union[Node, None]: # pragma: no cover
) -> Optional[Node]: # pragma: no cover
"""Find a node in the system with a specified unique ID.

This method searches only in the descendant nodes for the current system.
Expand All @@ -1119,7 +1119,7 @@ def find_node_by_uid(

Returns
-------
Union[Node, None]
Optional[Node]
``Node`` with the specified unique ID. If this ID isn't located in any
descendant node, ``None`` is returned.

Expand Down Expand Up @@ -1532,12 +1532,12 @@ def type(self) -> SlotType: # pragma: no cover

@property
@abstractmethod
def type_hint(self) -> Union[str, None]: # pragma: no cover
def type_hint(self) -> Optional[str]: # pragma: no cover
"""Get type hint.

Returns
-------
Union[str, None]
Optional[str]
Data type of the current slot, ``None`` if not specified.
"""
pass
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def create_slot(
node: Node,
name: str,
type_: SlotType,
type_hint: Union[str, None] = None,
type_hint: Optional[str] = None,
) -> Slot: # pragma: no cover
"""Create instance of new slot.

Expand All @@ -1594,7 +1594,7 @@ def create_slot(
Slot name.
type_ : SlotType
Slot type.
type_hint : Union[str, None], optional
type_hint : Optional[str], optional
Slot's expected data type, by default None.

Returns
Expand Down
20 changes: 10 additions & 10 deletions src/ansys/optislang/core/optislang.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,12 @@ def project(self) -> Optional[Project]:
return self.application.project

@property
def timeout(self) -> Union[float, None]:
def timeout(self) -> Optional[float]:
"""Get the timeout value for executing commands.

Returns
-------
timeout: Union[float, None]
timeout: Optional[float]
Timeout in seconds to perform commands. This value must be greater
than zero or ``None``. The default is ``None``. Another function
raises a timeout exception if the timeout value has elapsed before
Expand All @@ -470,12 +470,12 @@ def timeout(self) -> Union[float, None]:
return self.__osl_server.timeout

@timeout.setter
def timeout(self, timeout: Union[float, None] = None) -> None:
def timeout(self, timeout: Optional[float] = None) -> None:
"""Set the timeout value for the executing commands.

Parameters
----------
timeout: Union[float, None]
timeout: Optional[float], optional
Timeout in seconds to perform commands. This value must be greater
than zero or ``None``. The default is ``None``. Another function
raises a timeout exception if the timeout value has elapsed before
Expand All @@ -487,7 +487,7 @@ def timeout(self, timeout: Union[float, None] = None) -> None:
ValueError
Raised when the timeout value is less than or equal to 0.
TypeError
Raised when the timeout is not a Union[float, None].
Raised when the timeout is not a type of ``float`` or ``None``.
"""
self.__osl_server.timeout = timeout

Expand Down Expand Up @@ -563,12 +563,12 @@ def get_osl_version(self) -> OslVersion:
return self.__osl_server.osl_version

@deprecated(version="0.5.0", reason="Use :py:attr:`Optislang.timeout` instead.")
def get_timeout(self) -> Union[float, None]:
def get_timeout(self) -> Optional[float]:
"""Get the timeout value for executing commands.

Returns
-------
timeout: Union[float, None]
timeout: Optional[float]
Timeout in seconds to perform commands. This value must be greater
than zero or ``None``. The default is ``None``. Another function
raises a timeout exception if the timeout value has elapsed before
Expand Down Expand Up @@ -868,12 +868,12 @@ def save_copy(self, file_path: Union[str, Path]) -> None:
self.application.save_copy(file_path)

@deprecated(version="0.5.0", reason="Use :py:attr:`Optislang.timeout` instead.")
def set_timeout(self, timeout: Union[float, None] = None) -> None:
def set_timeout(self, timeout: Optional[float] = None) -> None:
"""Set the timeout value for the executing commands.

Parameters
----------
timeout: Union[float, None]
timeout: Optional[float]
Timeout in seconds to perform commands. This value must be greater
than zero or ``None``. The default is ``None``. Another function
raises a timeout exception if the timeout value has elapsed before
Expand All @@ -885,7 +885,7 @@ def set_timeout(self, timeout: Union[float, None] = None) -> None:
ValueError
Raised when the timeout value is less than or equal to 0.
TypeError
Raised when the timeout is not a Union[float, None].
Raised when the timeout is not type of ``float`` or ``None``.
"""
self.osl_server.timeout = timeout

Expand Down
36 changes: 18 additions & 18 deletions src/ansys/optislang/core/osl_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ def enable_tcp_server(self) -> bool:
return self.__enable_tcp_server

@property
def server_info(self) -> Union[Path, None]:
def server_info(self) -> Optional[Path]:
"""Path to the server information file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the server information file, if defined; ``None`` otherwise.
"""
return self.__server_info
Expand Down Expand Up @@ -566,12 +566,12 @@ def additional_args(self) -> Tuple[str, ...]:
return self.__additional_args

@property
def pid(self) -> Union[int, None]:
def pid(self) -> Optional[int]:
"""Process ID.

Returns
-------
Union[int, None]
Optional[int]
Process ID, if exists; ``None`` otherwise.
"""
return None if self.__process is None else self.__process.pid
Expand All @@ -588,79 +588,79 @@ def shutdown_on_finished(self) -> str:
return self.__shutdown_on_finished

@property
def import_project_properties_file(self) -> Union[Path, None]:
def import_project_properties_file(self) -> Optional[Path]:
"""Path to the project properties import file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the project properties import file, if defined; ``None`` otherwise.
"""
return self.__import_project_properties_file

@property
def export_project_properties_file(self) -> Union[Path, None]:
def export_project_properties_file(self) -> Optional[Path]:
"""Path to the project properties export file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the project properties export file, if defined; ``None`` otherwise.
"""
return self.__export_project_properties_file

@property
def import_placeholders_file(self) -> Union[Path, None]:
def import_placeholders_file(self) -> Optional[Path]:
"""Path to the placeholders import file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the placeholders import file, if defined; ``None`` otherwise.
"""
return self.__import_placeholders_file

@property
def export_placeholders_file(self) -> Union[Path, None]:
def export_placeholders_file(self) -> Optional[Path]:
"""Path to the placeholders export file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path, None]
Path to the placeholders export file, if defined; ``None`` otherwise.
"""
return self.__export_placeholders_file

@property
def output_file(self) -> Union[Path, None]:
def output_file(self) -> Optional[Path]:
"""Path to the output file for writing project run results to.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the output file for writing project run results to, if defined;
``None`` otherwise.
"""
return self.__output_file

@property
def dump_project_state(self) -> Union[Path, None]:
def dump_project_state(self) -> Optional[Path]:
"""Path to a project state dump file to export.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to a project state dump file to export, if defined; ``None`` otherwise.
"""
return self.__dump_project_state

@property
def opx_project_definition_file(self) -> Union[Path, None]:
def opx_project_definition_file(self) -> Optional[Path]:
"""Path to the OPX project definition file.

Returns
-------
Union[pathlib.Path, None]
Optional[pathlib.Path]
Path to the OPX project definition file, if defined;
``None`` otherwise.
"""
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/optislang/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from abc import ABC, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Optional, Sequence, Tuple, Union

if TYPE_CHECKING:
from ansys.optislang.core.io import RegisteredFile
Expand Down Expand Up @@ -103,12 +103,12 @@ def evaluate_design(
pass

@abstractmethod
def get_description(self) -> Union[str, None]: # pragma: no cover
def get_description(self) -> Optional[str]: # pragma: no cover
"""Get the description of the optiSLang project.

Returns
-------
Union[str, None]
Optional[str]
Description of the optiSLang project. If no project is loaded in optiSLang,
``None`` is returned.

Expand Down
Loading
Loading