Skip to content

Commit e2ebdd7

Browse files
committed
Resolve missing docstrings and minor lint issues
1 parent 64bcb02 commit e2ebdd7

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

tcod/map.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import warnings
6-
from typing import TYPE_CHECKING, Any, Literal
6+
from typing import TYPE_CHECKING, Any, Final, Literal
77

88
import numpy as np
99
from typing_extensions import deprecated
@@ -31,13 +31,6 @@ class Map:
3131
height (int): Height of the new Map.
3232
order (str): Which numpy memory order to use.
3333
34-
Attributes:
35-
width (int): Read only width of this Map.
36-
height (int): Read only height of this Map.
37-
transparent: A boolean array of transparent cells.
38-
walkable: A boolean array of walkable cells.
39-
fov: A boolean array of the cells lit by :any:'compute_fov'.
40-
4134
Example::
4235
4336
>>> import tcod
@@ -80,8 +73,10 @@ def __init__(
8073
order: Literal["C", "F"] = "C",
8174
) -> None:
8275
"""Initialize the map."""
83-
self.width = width
84-
self.height = height
76+
self.width: Final = width
77+
"""Read only width of this Map."""
78+
self.height: Final = height
79+
"""Read only height of this Map."""
8580
self._order: Literal["C", "F"] = tcod._internal.verify_order(order)
8681

8782
self._buffer: NDArray[np.bool_] = np.zeros((height, width, 3), dtype=np.bool_)
@@ -100,16 +95,19 @@ def __as_cdata(self) -> Any: # noqa: ANN401
10095

10196
@property
10297
def transparent(self) -> NDArray[np.bool_]:
98+
"""A boolean array of transparent cells."""
10399
buffer: np.ndarray[Any, np.dtype[np.bool_]] = self._buffer[:, :, 0]
104100
return buffer.T if self._order == "F" else buffer
105101

106102
@property
107103
def walkable(self) -> NDArray[np.bool_]:
104+
"""A boolean array of walkable cells."""
108105
buffer: np.ndarray[Any, np.dtype[np.bool_]] = self._buffer[:, :, 1]
109106
return buffer.T if self._order == "F" else buffer
110107

111108
@property
112109
def fov(self) -> NDArray[np.bool_]:
110+
"""A boolean array of the cells lit by :any:'compute_fov'."""
113111
buffer: np.ndarray[Any, np.dtype[np.bool_]] = self._buffer[:, :, 2]
114112
return buffer.T if self._order == "F" else buffer
115113

@@ -146,6 +144,7 @@ def compute_fov(
146144
lib.TCOD_map_compute_fov(self.map_c, x, y, radius, light_walls, algorithm)
147145

148146
def __setstate__(self, state: dict[str, Any]) -> None:
147+
"""Unpickle this instance."""
149148
if "_Map__buffer" in state: # Deprecated since 19.6
150149
state["_buffer"] = state.pop("_Map__buffer")
151150
if "buffer" in state: # Deprecated
@@ -159,6 +158,7 @@ def __setstate__(self, state: dict[str, Any]) -> None:
159158
self.map_c = self.__as_cdata()
160159

161160
def __getstate__(self) -> dict[str, Any]:
161+
"""Pickle this instance."""
162162
state = self.__dict__.copy()
163163
del state["map_c"]
164164
return state

tcod/noise.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Algorithm(enum.IntEnum):
6666
"""Wavelet noise."""
6767

6868
def __repr__(self) -> str:
69+
"""Return the string representation for this algorithm."""
6970
return f"tcod.noise.Algorithm.{self.name}"
7071

7172

@@ -88,6 +89,7 @@ class Implementation(enum.IntEnum):
8889
"""Turbulence noise implementation."""
8990

9091
def __repr__(self) -> str:
92+
"""Return the string representation for this implementation."""
9193
return f"tcod.noise.Implementation.{self.name}"
9294

9395

@@ -161,27 +163,30 @@ def __rng_from_seed(seed: None | int | tcod.random.Random) -> tcod.random.Random
161163
return seed
162164

163165
def __repr__(self) -> str:
166+
"""Return the string representation of this noise instance."""
164167
parameters = [
165168
f"dimensions={self.dimensions}",
166169
f"algorithm={self.algorithm!r}",
167170
f"implementation={Implementation(self.implementation)!r}",
168171
]
169-
if self.hurst != 0.5:
172+
if self.hurst != 0.5: # noqa: PLR2004 # Default value
170173
parameters.append(f"hurst={self.hurst}")
171-
if self.lacunarity != 2:
174+
if self.lacunarity != 2: # noqa: PLR2004 # Default value
172175
parameters.append(f"lacunarity={self.lacunarity}")
173-
if self.octaves != 4:
176+
if self.octaves != 4: # noqa: PLR2004 # Default value
174177
parameters.append(f"octaves={self.octaves}")
175178
if self._seed is not None:
176179
parameters.append(f"seed={self._seed}")
177180
return f"tcod.noise.Noise({', '.join(parameters)})"
178181

179182
@property
180183
def dimensions(self) -> int:
184+
"""Number of dimensions supported by this noise generator."""
181185
return int(self._tdl_noise_c.dimensions)
182186

183187
@property
184188
def algorithm(self) -> int:
189+
"""Current selected algorithm. Can be changed."""
185190
noise_type = self.noise_c.noise_type
186191
return Algorithm(noise_type) if noise_type else Algorithm.SIMPLEX
187192

@@ -191,6 +196,7 @@ def algorithm(self, value: int) -> None:
191196

192197
@property
193198
def implementation(self) -> int:
199+
"""Current selected implementation. Can be changed."""
194200
return Implementation(self._tdl_noise_c.implementation)
195201

196202
@implementation.setter
@@ -202,14 +208,17 @@ def implementation(self, value: int) -> None:
202208

203209
@property
204210
def hurst(self) -> float:
211+
"""Noise hurst exponent. Can be changed."""
205212
return float(self.noise_c.H)
206213

207214
@property
208215
def lacunarity(self) -> float:
216+
"""Noise lacunarity. Can be changed."""
209217
return float(self.noise_c.lacunarity)
210218

211219
@property
212220
def octaves(self) -> float:
221+
"""Level of detail on fBm and turbulence implementations. Can be changed."""
213222
return float(self._tdl_noise_c.octaves)
214223

215224
@octaves.setter
@@ -343,6 +352,7 @@ def sample_ogrid(self, ogrid: Sequence[ArrayLike]) -> NDArray[np.float32]:
343352
return out
344353

345354
def __getstate__(self) -> dict[str, Any]:
355+
"""Support picking this instance."""
346356
state = self.__dict__.copy()
347357
if self.dimensions < 4 and self.noise_c.waveletTileData == ffi.NULL: # noqa: PLR2004
348358
# Trigger a side effect of wavelet, so that copies will be synced.
@@ -374,6 +384,7 @@ def __getstate__(self) -> dict[str, Any]:
374384
return state
375385

376386
def __setstate__(self, state: dict[str, Any]) -> None:
387+
"""Unpickle this instance."""
377388
if isinstance(state, tuple): # deprecated format
378389
return self._setstate_old(state)
379390
# unpack wavelet tile data if it exists

tcod/path.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def __init__(
112112
callback: Callable[[int, int, int, int], float],
113113
shape: tuple[int, int],
114114
) -> None:
115+
"""Initialize this callback."""
115116
self.callback = callback
116117
super().__init__(callback, shape)
117118

@@ -139,6 +140,7 @@ def __new__(cls, array: ArrayLike) -> Self:
139140
return np.asarray(array).view(cls)
140141

141142
def __repr__(self) -> str:
143+
"""Return the string representation of this object."""
142144
return f"{self.__class__.__name__}({repr(self.view(np.ndarray))!r})"
143145

144146
def get_tcod_path_ffi(self) -> tuple[Any, Any, tuple[int, int]]:
@@ -1068,10 +1070,12 @@ def __init__(self, *, cost: ArrayLike, cardinal: int, diagonal: int, greed: int
10681070

10691071
@property
10701072
def ndim(self) -> int:
1073+
"""Number of dimensions."""
10711074
return 2
10721075

10731076
@property
10741077
def shape(self) -> tuple[int, int]:
1078+
"""Shape of this graph."""
10751079
return self._shape
10761080

10771081
@property

tcod/sdl/joystick.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Joystick:
103103
"""Currently opened joysticks."""
104104

105105
def __init__(self, sdl_joystick_p: Any) -> None: # noqa: ANN401
106+
"""Wrap an SDL joystick C pointer."""
106107
self.sdl_joystick_p: Final = sdl_joystick_p
107108
"""The CFFI pointer to an SDL_Joystick struct."""
108109
self.axes: Final[int] = _check_int(lib.SDL_GetNumJoystickAxes(self.sdl_joystick_p), failure=-1)
@@ -135,11 +136,13 @@ def _from_instance_id(cls, instance_id: int) -> Joystick:
135136
return cls._by_instance_id[instance_id]
136137

137138
def __eq__(self, other: object) -> bool:
139+
"""Return True if `self` and `other` refer to the same joystick."""
138140
if isinstance(other, Joystick):
139141
return self.id == other.id
140142
return NotImplemented
141143

142144
def __hash__(self) -> int:
145+
"""Return the joystick id as a hash."""
143146
return hash(self.id)
144147

145148
def _get_guid(self) -> str:
@@ -173,6 +176,7 @@ class GameController:
173176
"""Currently opened controllers."""
174177

175178
def __init__(self, sdl_controller_p: Any) -> None: # noqa: ANN401
179+
"""Wrap an SDL controller C pointer."""
176180
self.sdl_controller_p: Final = sdl_controller_p
177181
self.joystick: Final = Joystick(lib.SDL_GetGamepadJoystick(self.sdl_controller_p))
178182
"""The :any:`Joystick` associated with this controller."""
@@ -200,11 +204,13 @@ def get_axis(self, axis: ControllerAxis) -> int:
200204
return int(lib.SDL_GetGamepadAxis(self.sdl_controller_p, axis))
201205

202206
def __eq__(self, other: object) -> bool:
207+
"""Return True if `self` and `other` are both controllers referring to the same joystick."""
203208
if isinstance(other, GameController):
204209
return self.joystick.id == other.joystick.id
205210
return NotImplemented
206211

207212
def __hash__(self) -> int:
213+
"""Return the joystick id as a hash."""
208214
return hash(self.joystick.id)
209215

210216
# These could exist as convenience functions, but the get_X functions are probably better.

tcod/sdl/mouse.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Cursor:
2828
"""A cursor icon for use with :any:`set_cursor`."""
2929

3030
def __init__(self, sdl_cursor_p: Any) -> None: # noqa: ANN401
31+
"""Wrap an SDL cursor C pointer."""
3132
if ffi.typeof(sdl_cursor_p) is not ffi.typeof("struct SDL_Cursor*"):
3233
msg = f"Expected a {ffi.typeof('struct SDL_Cursor*')} type (was {ffi.typeof(sdl_cursor_p)})."
3334
raise TypeError(msg)
@@ -37,9 +38,13 @@ def __init__(self, sdl_cursor_p: Any) -> None: # noqa: ANN401
3738
self.p = sdl_cursor_p
3839

3940
def __eq__(self, other: object) -> bool:
40-
return bool(self.p == getattr(other, "p", None))
41+
"""Return True if `self` is the same cursor as `other`."""
42+
if isinstance(other, Cursor):
43+
return bool(self.p == getattr(other, "p", None))
44+
return NotImplemented
4145

4246
def __hash__(self) -> int:
47+
"""Returns the hash of this objects C pointer."""
4348
return hash(self.p)
4449

4550
@classmethod

0 commit comments

Comments
 (0)