Skip to content

Commit

Permalink
TYP: Add retunr type hints for functions that return None
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jan 8, 2025
1 parent a9d26a8 commit b479656
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pygmt/_show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _check_ghostscript_version(gs_version: str | None) -> str | None:
return None


def show_versions(file: TextIO | None = sys.stdout):
def show_versions(file: TextIO | None = sys.stdout) -> None:
"""
Print various dependency versions which are useful when submitting bug reports.
Expand Down
18 changes: 12 additions & 6 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def get_libgmt_func(
function.restype = restype
return function

def create(self, name: str):
def create(self, name: str) -> None:
"""
Create a new GMT C API session.
Expand Down Expand Up @@ -594,7 +594,7 @@ def get_common(self, option: str) -> bool | int | float | np.ndarray:
case _: # 'status' is the option value (in integer type).
return status

def call_module(self, module: str, args: str | list[str]):
def call_module(self, module: str, args: str | list[str]) -> None:
"""
Call a GMT module with the given arguments.
Expand Down Expand Up @@ -946,7 +946,9 @@ def _check_dtype_and_dim(self, array: np.ndarray, ndim: int) -> int:
raise GMTInvalidInput(msg)
return self[DTYPES[dtype]]

def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray):
def put_vector(
self, dataset: ctp.c_void_p, column: int, vector: np.ndarray
) -> None:
r"""
Attach a 1-D numpy array as a column on a GMT dataset.
Expand Down Expand Up @@ -1005,7 +1007,9 @@ def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray):
)
raise GMTCLibError(msg)

def put_strings(self, dataset: ctp.c_void_p, family: str, strings: np.ndarray):
def put_strings(
self, dataset: ctp.c_void_p, family: str, strings: np.ndarray
) -> None:
"""
Attach a 1-D numpy array of dtype str as a column on a GMT dataset.
Expand Down Expand Up @@ -1059,7 +1063,9 @@ def put_strings(self, dataset: ctp.c_void_p, family: str, strings: np.ndarray):
msg = f"Failed to put strings of type {strings.dtype} into dataset."
raise GMTCLibError(msg)

def put_matrix(self, dataset: ctp.c_void_p, matrix: np.ndarray, pad: int = 0):
def put_matrix(
self, dataset: ctp.c_void_p, matrix: np.ndarray, pad: int = 0
) -> None:
"""
Attach a 2-D numpy array to a GMT dataset.
Expand Down Expand Up @@ -1204,7 +1210,7 @@ def read_data(
raise GMTCLibError(msg)
return ctp.cast(data_ptr, ctp.POINTER(dtype))

def write_data(self, family, geometry, mode, wesn, output, data):
def write_data(self, family, geometry, mode, wesn, output, data) -> None:
"""
Write a GMT data container to a file.
Expand Down
12 changes: 6 additions & 6 deletions pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ class Figure:
122.94, 145.82, 20.53, 45.52
"""

def __init__(self):
def __init__(self) -> None:
self._name = unique_name()
self._preview_dir = TemporaryDirectory(prefix=f"{self._name}-preview-")
self._activate_figure()

def __del__(self):
def __del__(self) -> None:
"""
Clean up the temporary directory that stores the previews.
"""
if hasattr(self, "_preview_dir"):
self._preview_dir.cleanup()

def _activate_figure(self):
def _activate_figure(self) -> None:
"""
Start and/or activate the current figure.
Expand Down Expand Up @@ -144,7 +144,7 @@ def savefig(
show: bool = False,
worldfile: bool = False,
**kwargs,
):
) -> None:
"""
Save the figure to an image file.
Expand Down Expand Up @@ -268,7 +268,7 @@ def show(
width: int = 500,
waiting: float = 0.5,
**kwargs,
):
) -> None:
"""
Display a preview of the figure.
Expand Down Expand Up @@ -442,7 +442,7 @@ def _repr_html_(self) -> str:
)


def set_display(method: Literal["external", "notebook", "none", None] = None):
def set_display(method: Literal["external", "notebook", "none", None] = None) -> None:
"""
Set the display method when calling :meth:`pygmt.Figure.show`.
Expand Down
2 changes: 1 addition & 1 deletion pygmt/helpers/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pygmt.src import which


def cache_data():
def cache_data() -> None:
"""
Download GMT remote data files used in PyGMT tests and docs to cache folder.
"""
Expand Down
2 changes: 1 addition & 1 deletion pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GMTTempFile:
[0. 0. 0.] [1. 1. 1.] [2. 2. 2.]
"""

def __init__(self, prefix: str = "pygmt-", suffix: str = ".txt"):
def __init__(self, prefix: str = "pygmt-", suffix: str = ".txt") -> None:
"""
Initialize the object.
"""
Expand Down
4 changes: 2 additions & 2 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

def _validate_data_input(
data=None, x=None, y=None, z=None, required_z=False, required_data=True, kind=None
):
) -> None:
"""
Check if the combination of data/x/y/z is valid.
Expand Down Expand Up @@ -552,7 +552,7 @@ def is_nonstr_iter(value):
return isinstance(value, Iterable) and not isinstance(value, str)


def launch_external_viewer(fname: str, waiting: float = 0):
def launch_external_viewer(fname: str, waiting: float = 0) -> None:
"""
Open a file in an external viewer program.
Expand Down
4 changes: 2 additions & 2 deletions pygmt/session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pygmt.helpers import unique_name


def begin():
def begin() -> None:
"""
Initiate a new GMT modern mode session.
Expand All @@ -28,7 +28,7 @@ def begin():
lib.call_module(module="set", args=["GMT_COMPATIBILITY=6"])


def end():
def end() -> None:
"""
Terminate the GMT modern mode session created by :func:`pygmt.begin`.
Expand Down

0 comments on commit b479656

Please sign in to comment.