Skip to content

Commit 7a9a134

Browse files
committed
Update type hints for NumPy 1.22.4.
Fix broken assert in Renderer.read_pixels. Show error codes by default in MyPy.
1 parent 751901e commit 7a9a134

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

examples/samples_tcod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def interpolate_corner_colors(self) -> None:
140140
def darken_background_characters(self) -> None:
141141
# darken background characters
142142
sample_console.fg[:] = sample_console.bg[:]
143-
sample_console.fg[:] //= 2
143+
sample_console.fg[:] //= 2 # type: ignore[arg-type] # https://github.com/numpy/numpy/issues/21592
144144

145145
def randomize_sample_conole(self) -> None:
146146
# randomize sample console characters

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ max-line-length = 130
1515
[mypy]
1616
python_version = 3.8
1717
warn_unused_configs = True
18+
show_error_codes = True
1819
disallow_subclassing_any = True
1920
disallow_any_generics = True
2021
disallow_untyped_calls = True

tcod/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def ch(self) -> NDArray[np.intc]:
243243
Index this array with ``console.ch[i, j] # order='C'`` or
244244
``console.ch[x, y] # order='F'``.
245245
"""
246-
return self._tiles["ch"].T if self._order == "F" else self._tiles["ch"] # type: ignore
246+
return self._tiles["ch"].T if self._order == "F" else self._tiles["ch"]
247247

248248
@property # type: ignore
249249
@deprecate("This attribute has been renamed to `rgba`.")

tcod/path.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _compile_cost_edges(edge_map: Any) -> Tuple[Any, int]:
344344
edge_array = np.transpose(edge_nz)
345345
edge_array -= edge_center
346346
c_edges = ffi.new("int[]", len(edge_array) * 3)
347-
edges = np.frombuffer(ffi.buffer(c_edges), dtype=np.intc).reshape(len(edge_array), 3) # type: ignore
347+
edges = np.frombuffer(ffi.buffer(c_edges), dtype=np.intc).reshape(len(edge_array), 3)
348348
edges[:, :2] = edge_array
349349
edges[:, 2] = edge_map[edge_nz]
350350
return c_edges, len(edge_array)
@@ -1148,7 +1148,7 @@ def traversal(self) -> NDArray[Any]:
11481148
"""
11491149
if self._order == "F":
11501150
axes = range(self._travel.ndim)
1151-
return self._travel.transpose((*axes[-2::-1], axes[-1]))[..., ::-1] # type: ignore
1151+
return self._travel.transpose((*axes[-2::-1], axes[-1]))[..., ::-1]
11521152
return self._travel
11531153

11541154
def clear(self) -> None:
@@ -1320,7 +1320,7 @@ def path_from(self, index: Tuple[int, ...]) -> NDArray[Any]:
13201320
ffi.from_buffer("int*", path),
13211321
)
13221322
)
1323-
return path[:, ::-1] if self._order == "F" else path # type: ignore
1323+
return path[:, ::-1] if self._order == "F" else path
13241324

13251325
def path_to(self, index: Tuple[int, ...]) -> NDArray[Any]:
13261326
"""Return the shortest path from the nearest root to `index`.
@@ -1347,4 +1347,4 @@ def path_to(self, index: Tuple[int, ...]) -> NDArray[Any]:
13471347
>>> pf.path_to((0, 0))[1:].tolist() # Exclude the starting point so that a blocked path is an empty list.
13481348
[]
13491349
""" # noqa: E501
1350-
return self.path_from(index)[::-1] # type: ignore
1350+
return self.path_from(index)[::-1]

tcod/sdl/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def read_pixels(
508508
out = np.empty((height, width, 3), dtype=np.uint8)
509509
else:
510510
raise TypeError("Pixel format not supported yet.")
511-
assert out.shape[:2] == height, width
511+
assert out.shape[:2] == (height, width)
512512
assert out[0].flags.c_contiguous
513513
_check(lib.SDL_RenderReadPixels(self.p, format, ffi.cast("void*", out.ctypes.data), out.strides[0]))
514514
return out

tcod/tileset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def procedural_block_elements(*, tileset: Tileset) -> None:
428428
(0x259F, 0b0111), # "▟" Quadrant upper right and lower left and lower right.
429429
):
430430
alpha: NDArray[np.uint8] = np.asarray((quadrants & quad_mask) != 0, dtype=np.uint8)
431-
alpha *= 255
431+
alpha *= 255 # type: ignore[arg-type] # https://github.com/numpy/numpy/issues/21592
432432
tileset.set_tile(codepoint, alpha)
433433

434434
for codepoint, axis, fraction, negative in (

0 commit comments

Comments
 (0)