Skip to content

Commit c8103fd

Browse files
committed
Resolve remaining warnings in console module
1 parent 3a21c6d commit c8103fd

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

tcod/console.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _init_setup_console_data(self, order: Literal["C", "F"] = "C") -> None:
193193
else:
194194
self._console_data = ffi.cast("struct TCOD_Console*", self.console_c)
195195

196-
self._tiles: NDArray[Any] = np.frombuffer( # type: ignore
196+
self._tiles = np.frombuffer(
197197
ffi.buffer(self._console_data.tiles[0 : self.width * self.height]),
198198
dtype=self.DTYPE,
199199
).reshape((self.height, self.width))
@@ -203,12 +203,12 @@ def _init_setup_console_data(self, order: Literal["C", "F"] = "C") -> None:
203203
@property
204204
def width(self) -> int:
205205
"""The width of this Console."""
206-
return lib.TCOD_console_get_width(self.console_c) # type: ignore
206+
return int(lib.TCOD_console_get_width(self.console_c))
207207

208208
@property
209209
def height(self) -> int:
210210
"""The height of this Console."""
211-
return lib.TCOD_console_get_height(self.console_c) # type: ignore
211+
return int(lib.TCOD_console_get_height(self.console_c))
212212

213213
@property
214214
def bg(self) -> NDArray[np.uint8]:
@@ -402,7 +402,7 @@ def default_bg_blend(self) -> int:
402402
.. deprecated:: 8.5
403403
These should not be used. Prefer passing defaults as kwargs.
404404
"""
405-
return self._console_data.bkgnd_flag # type: ignore
405+
return int(self._console_data.bkgnd_flag)
406406

407407
@default_bg_blend.setter
408408
@deprecated(_DEPRECATE_CONSOLE_DEFAULTS_MSG, category=FutureWarning)
@@ -416,7 +416,7 @@ def default_alignment(self) -> int:
416416
.. deprecated:: 8.5
417417
These should not be used. Prefer passing defaults as kwargs.
418418
"""
419-
return self._console_data.alignment # type: ignore
419+
return int(self._console_data.alignment)
420420

421421
@default_alignment.setter
422422
@deprecated(_DEPRECATE_CONSOLE_DEFAULTS_MSG, category=FutureWarning)
@@ -434,8 +434,8 @@ def __clear_warning(self, name: str, value: tuple[int, int, int]) -> None:
434434
def clear(
435435
self,
436436
ch: int = 0x20,
437-
fg: tuple[int, int, int] = ..., # type: ignore
438-
bg: tuple[int, int, int] = ..., # type: ignore
437+
fg: tuple[int, int, int] = ..., # type: ignore[assignment]
438+
bg: tuple[int, int, int] = ..., # type: ignore[assignment]
439439
) -> None:
440440
"""Reset all values in this console to a single value.
441441
@@ -454,11 +454,11 @@ def clear(
454454
Added the `ch`, `fg`, and `bg` parameters.
455455
Non-white-on-black default values are deprecated.
456456
"""
457-
if fg is ...: # type: ignore
457+
if fg is ...: # type: ignore[comparison-overlap]
458458
fg = self.default_fg
459459
if fg != (255, 255, 255):
460460
self.__clear_warning("fg", fg)
461-
if bg is ...: # type: ignore
461+
if bg is ...: # type: ignore[comparison-overlap]
462462
bg = self.default_bg
463463
if bg != (0, 0, 0):
464464
self.__clear_warning("bg", bg)
@@ -657,7 +657,7 @@ def rect( # noqa: PLR0913
657657
y: int,
658658
width: int,
659659
height: int,
660-
clear: bool,
660+
clear: bool, # noqa: FBT001
661661
bg_blend: int = tcod.constants.BKGND_DEFAULT,
662662
) -> None:
663663
"""Draw a the background color on a rect optionally clearing the text.
@@ -750,7 +750,7 @@ def print_frame( # noqa: PLR0913
750750
width: int,
751751
height: int,
752752
string: str = "",
753-
clear: bool = True,
753+
clear: bool = True, # noqa: FBT001, FBT002
754754
bg_blend: int = tcod.constants.BKGND_DEFAULT,
755755
) -> None:
756756
"""Draw a framed rectangle with optional text.
@@ -831,11 +831,11 @@ def blit( # noqa: PLR0913
831831
# The old syntax is easy to detect and correct.
832832
if hasattr(src_y, "console_c"):
833833
(src_x, src_y, width, height, dest, dest_x, dest_y) = (
834-
dest, # type: ignore
834+
dest, # type: ignore[assignment]
835835
dest_x,
836836
dest_y,
837837
src_x,
838-
src_y, # type: ignore
838+
src_y, # type: ignore[assignment]
839839
width,
840840
height,
841841
)
@@ -933,6 +933,7 @@ def __bool__(self) -> bool:
933933
return bool(self.console_c != ffi.NULL)
934934

935935
def __getstate__(self) -> dict[str, Any]:
936+
"""Support serialization via :mod:`pickle`."""
936937
state = self.__dict__.copy()
937938
del state["console_c"]
938939
state["_console_data"] = {
@@ -948,6 +949,7 @@ def __getstate__(self) -> dict[str, Any]:
948949
return state
949950

950951
def __setstate__(self, state: dict[str, Any]) -> None:
952+
"""Support serialization via :mod:`pickle`."""
951953
self._key_color = None
952954
if "_tiles" not in state:
953955
tiles: NDArray[Any] = np.ndarray((self.height, self.width), dtype=self.DTYPE)
@@ -967,12 +969,7 @@ def __setstate__(self, state: dict[str, Any]) -> None:
967969

968970
def __repr__(self) -> str:
969971
"""Return a string representation of this console."""
970-
return "tcod.console.Console(width=%i, height=%i, order=%r,buffer=\n%r)" % (
971-
self.width,
972-
self.height,
973-
self._order,
974-
self.rgba,
975-
)
972+
return f"tcod.console.Console(width={self.width}, height={self.height}, order={self._order!r},buffer=\n{self.rgba!r})"
976973

977974
def __str__(self) -> str:
978975
"""Return a simplified representation of this consoles contents."""
@@ -1197,7 +1194,7 @@ def draw_frame( # noqa: PLR0913
11971194
width: int,
11981195
height: int,
11991196
title: str = "",
1200-
clear: bool = True,
1197+
clear: bool = True, # noqa: FBT001, FBT002
12011198
fg: tuple[int, int, int] | None = None,
12021199
bg: tuple[int, int, int] | None = None,
12031200
bg_blend: int = tcod.constants.BKGND_SET,

0 commit comments

Comments
 (0)