Skip to content

Commit 3d4baa6

Browse files
authored
TYP: Add type hints to the GMT accessors (#3816)
1 parent e66589f commit 3d4baa6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pygmt/accessors.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class GMTDataArrayAccessor:
126126
(<GridRegistration.GRIDLINE: 0>, <GridType.GEOGRAPHIC: 1>)
127127
"""
128128

129-
def __init__(self, xarray_obj):
129+
def __init__(self, xarray_obj: xr.DataArray):
130130
self._obj = xarray_obj
131131

132132
# Default to Gridline registration and Cartesian grid type
@@ -137,19 +137,19 @@ def __init__(self, xarray_obj):
137137
# two columns of the shortened summary information of grdinfo.
138138
if (_source := self._obj.encoding.get("source")) and Path(_source).exists():
139139
with contextlib.suppress(ValueError):
140-
self._registration, self._gtype = map(
140+
self._registration, self._gtype = map( # type: ignore[assignment]
141141
int, grdinfo(_source, per_column="n").split()[-2:]
142142
)
143143

144144
@property
145-
def registration(self):
145+
def registration(self) -> GridRegistration:
146146
"""
147147
Grid registration type :class:`pygmt.enums.GridRegistration`.
148148
"""
149149
return self._registration
150150

151151
@registration.setter
152-
def registration(self, value):
152+
def registration(self, value: GridRegistration | int):
153153
# TODO(Python>=3.12): Simplify to `if value not in GridRegistration`.
154154
if value not in GridRegistration.__members__.values():
155155
msg = (
@@ -160,14 +160,14 @@ def registration(self, value):
160160
self._registration = GridRegistration(value)
161161

162162
@property
163-
def gtype(self):
163+
def gtype(self) -> GridType:
164164
"""
165165
Grid coordinate system type :class:`pygmt.enums.GridType`.
166166
"""
167167
return self._gtype
168168

169169
@gtype.setter
170-
def gtype(self, value):
170+
def gtype(self, value: GridType | int):
171171
# TODO(Python>=3.12): Simplify to `if value not in GridType`.
172172
if value not in GridType.__members__.values():
173173
msg = (

0 commit comments

Comments
 (0)