Skip to content

Commit 1d50ffb

Browse files
authored
TYP: Add return type hints for functions that return None (#3754)
1 parent a9d26a8 commit 1d50ffb

File tree

7 files changed

+25
-19
lines changed

7 files changed

+25
-19
lines changed

pygmt/_show_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _check_ghostscript_version(gs_version: str | None) -> str | None:
8585
return None
8686

8787

88-
def show_versions(file: TextIO | None = sys.stdout):
88+
def show_versions(file: TextIO | None = sys.stdout) -> None:
8989
"""
9090
Print various dependency versions which are useful when submitting bug reports.
9191

pygmt/clib/session.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def get_libgmt_func(
327327
function.restype = restype
328328
return function
329329

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

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

949-
def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray):
949+
def put_vector(
950+
self, dataset: ctp.c_void_p, column: int, vector: np.ndarray
951+
) -> None:
950952
r"""
951953
Attach a 1-D numpy array as a column on a GMT dataset.
952954
@@ -1005,7 +1007,9 @@ def put_vector(self, dataset: ctp.c_void_p, column: int, vector: np.ndarray):
10051007
)
10061008
raise GMTCLibError(msg)
10071009

1008-
def put_strings(self, dataset: ctp.c_void_p, family: str, strings: np.ndarray):
1010+
def put_strings(
1011+
self, dataset: ctp.c_void_p, family: str, strings: np.ndarray
1012+
) -> None:
10091013
"""
10101014
Attach a 1-D numpy array of dtype str as a column on a GMT dataset.
10111015
@@ -1059,7 +1063,9 @@ def put_strings(self, dataset: ctp.c_void_p, family: str, strings: np.ndarray):
10591063
msg = f"Failed to put strings of type {strings.dtype} into dataset."
10601064
raise GMTCLibError(msg)
10611065

1062-
def put_matrix(self, dataset: ctp.c_void_p, matrix: np.ndarray, pad: int = 0):
1066+
def put_matrix(
1067+
self, dataset: ctp.c_void_p, matrix: np.ndarray, pad: int = 0
1068+
) -> None:
10631069
"""
10641070
Attach a 2-D numpy array to a GMT dataset.
10651071
@@ -1204,7 +1210,7 @@ def read_data(
12041210
raise GMTCLibError(msg)
12051211
return ctp.cast(data_ptr, ctp.POINTER(dtype))
12061212

1207-
def write_data(self, family, geometry, mode, wesn, output, data):
1213+
def write_data(self, family, geometry, mode, wesn, output, data) -> None:
12081214
"""
12091215
Write a GMT data container to a file.
12101216

pygmt/figure.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ class Figure:
9595
122.94, 145.82, 20.53, 45.52
9696
"""
9797

98-
def __init__(self):
98+
def __init__(self) -> None:
9999
self._name = unique_name()
100100
self._preview_dir = TemporaryDirectory(prefix=f"{self._name}-preview-")
101101
self._activate_figure()
102102

103-
def __del__(self):
103+
def __del__(self) -> None:
104104
"""
105105
Clean up the temporary directory that stores the previews.
106106
"""
107107
if hasattr(self, "_preview_dir"):
108108
self._preview_dir.cleanup()
109109

110-
def _activate_figure(self):
110+
def _activate_figure(self) -> None:
111111
"""
112112
Start and/or activate the current figure.
113113
@@ -144,7 +144,7 @@ def savefig(
144144
show: bool = False,
145145
worldfile: bool = False,
146146
**kwargs,
147-
):
147+
) -> None:
148148
"""
149149
Save the figure to an image file.
150150
@@ -268,7 +268,7 @@ def show(
268268
width: int = 500,
269269
waiting: float = 0.5,
270270
**kwargs,
271-
):
271+
) -> None:
272272
"""
273273
Display a preview of the figure.
274274
@@ -442,7 +442,7 @@ def _repr_html_(self) -> str:
442442
)
443443

444444

445-
def set_display(method: Literal["external", "notebook", "none", None] = None):
445+
def set_display(method: Literal["external", "notebook", "none", None] = None) -> None:
446446
"""
447447
Set the display method when calling :meth:`pygmt.Figure.show`.
448448

pygmt/helpers/caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pygmt.src import which
66

77

8-
def cache_data():
8+
def cache_data() -> None:
99
"""
1010
Download GMT remote data files used in PyGMT tests and docs to cache folder.
1111
"""

pygmt/helpers/tempfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class GMTTempFile:
5959
[0. 0. 0.] [1. 1. 1.] [2. 2. 2.]
6060
"""
6161

62-
def __init__(self, prefix: str = "pygmt-", suffix: str = ".txt"):
62+
def __init__(self, prefix: str = "pygmt-", suffix: str = ".txt") -> None:
6363
"""
6464
Initialize the object.
6565
"""

pygmt/helpers/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
def _validate_data_input(
4545
data=None, x=None, y=None, z=None, required_z=False, required_data=True, kind=None
46-
):
46+
) -> None:
4747
"""
4848
Check if the combination of data/x/y/z is valid.
4949
@@ -552,7 +552,7 @@ def is_nonstr_iter(value):
552552
return isinstance(value, Iterable) and not isinstance(value, str)
553553

554554

555-
def launch_external_viewer(fname: str, waiting: float = 0):
555+
def launch_external_viewer(fname: str, waiting: float = 0) -> None:
556556
"""
557557
Open a file in an external viewer program.
558558

pygmt/session_management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pygmt.helpers import unique_name
1010

1111

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

3030

31-
def end():
31+
def end() -> None:
3232
"""
3333
Terminate the GMT modern mode session created by :func:`pygmt.begin`.
3434

0 commit comments

Comments
 (0)