Skip to content

Commit 1083185

Browse files
committed
Clean up more warnings
Mostly suppressing old unfixable API issues Minor type improvements with map copying and tile accessing
1 parent a0bcee8 commit 1083185

25 files changed

+242
-208
lines changed

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"aarch",
2121
"ADDA",
2222
"ADDALPHA",
23+
"addoption",
2324
"addopts",
2425
"addressof",
2526
"addsub",
@@ -146,6 +147,7 @@
146147
"DVLINE",
147148
"elif",
148149
"Emscripten",
150+
"EMSDK",
149151
"ENDCALL",
150152
"endianness",
151153
"epel",
@@ -207,6 +209,7 @@
207209
"IJKL",
208210
"imageio",
209211
"imread",
212+
"includepath",
210213
"INCOL",
211214
"INPUTTYPE",
212215
"INROW",
@@ -308,6 +311,7 @@
308311
"MMASK",
309312
"modindex",
310313
"moduleauthor",
314+
"modversion",
311315
"MOUSEBUTTONDOWN",
312316
"MOUSEBUTTONUP",
313317
"MOUSEMOTION",
@@ -328,6 +332,7 @@
328332
"neww",
329333
"noarchive",
330334
"NODISCARD",
335+
"NOLONGLONG",
331336
"NOMESSAGE",
332337
"Nonrepresentable",
333338
"NONUSBACKSLASH",
@@ -350,6 +355,7 @@
350355
"pagerefs",
351356
"PAGEUP",
352357
"papersize",
358+
"passthru",
353359
"PATCHLEVEL",
354360
"pathfinding",
355361
"pathlib",
@@ -361,6 +367,7 @@
361367
"PIXELFORMAT",
362368
"PLUSMINUS",
363369
"pointsize",
370+
"popleft",
364371
"PRESENTVSYNC",
365372
"PRINTF",
366373
"printn",
@@ -378,6 +385,7 @@
378385
"pypiwin",
379386
"pypy",
380387
"pytest",
388+
"pytestmark",
381389
"PYTHONHASHSEED",
382390
"PYTHONOPTIMIZE",
383391
"Pyup",
@@ -393,6 +401,7 @@
393401
"Redistributable",
394402
"redistributables",
395403
"repr",
404+
"rexpaint",
396405
"rgba",
397406
"RGUI",
398407
"RHYPER",
@@ -447,6 +456,8 @@
447456
"sphinxstrong",
448457
"sphinxtitleref",
449458
"staticmethod",
459+
"stdarg",
460+
"stddef",
450461
"stdeb",
451462
"struct",
452463
"structs",
@@ -498,6 +509,7 @@
498509
"VERTICALBAR",
499510
"vflip",
500511
"viewcode",
512+
"VITAFILE",
501513
"vline",
502514
"VOLUMEDOWN",
503515
"VOLUMEUP",
@@ -508,6 +520,7 @@
508520
"WAITARROW",
509521
"WASD",
510522
"waterlevel",
523+
"WINAPI",
511524
"windowclose",
512525
"windowenter",
513526
"WINDOWEVENT",
@@ -526,6 +539,7 @@
526539
"windowshown",
527540
"windowsizechanged",
528541
"windowtakefocus",
542+
"xcframework",
529543
"Xcursor",
530544
"xdst",
531545
"Xext",

build_libtcod.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
import re
1212
import subprocess
1313
import sys
14-
from collections.abc import Iterable, Iterator
1514
from pathlib import Path
16-
from typing import Any, ClassVar
15+
from typing import TYPE_CHECKING, Any, ClassVar, Final
1716

1817
import attrs
1918
import pycparser # type: ignore[import-untyped]
@@ -27,6 +26,9 @@
2726

2827
import build_sdl
2928

29+
if TYPE_CHECKING:
30+
from collections.abc import Iterable, Iterator
31+
3032
Py_LIMITED_API = 0x03100000
3133

3234
HEADER_PARSE_PATHS = ("tcod/", "libtcod/src/libtcod/")
@@ -269,7 +271,7 @@ def find_sdl_attrs(prefix: str) -> Iterator[tuple[str, int | str | Any]]:
269271
270272
`prefix` is used to filter out which names to copy.
271273
"""
272-
from tcod._libtcod import lib
274+
from tcod._libtcod import lib # noqa: PLC0415
273275

274276
if prefix.startswith("SDL_"):
275277
name_starts_at = 4
@@ -320,12 +322,14 @@ def parse_sdl_attrs(prefix: str, all_names: list[str] | None) -> tuple[str, str]
320322
]
321323

322324

325+
RE_CONSTANTS_ALL: Final = re.compile(
326+
r"(.*# --- From constants.py ---).*(# --- End constants.py ---.*)",
327+
re.DOTALL,
328+
)
329+
330+
323331
def update_module_all(filename: Path, new_all: str) -> None:
324332
"""Update the __all__ of a file with the constants from new_all."""
325-
RE_CONSTANTS_ALL = re.compile(
326-
r"(.*# --- From constants.py ---).*(# --- End constants.py ---.*)",
327-
re.DOTALL,
328-
)
329333
match = RE_CONSTANTS_ALL.match(filename.read_text(encoding="utf-8"))
330334
assert match, f"Can't determine __all__ subsection in {filename}!"
331335
header, footer = match.groups()
@@ -346,8 +350,8 @@ def generate_enums(prefix: str) -> Iterator[str]:
346350

347351
def write_library_constants() -> None:
348352
"""Write libtcod constants into the tcod.constants module."""
349-
import tcod.color
350-
from tcod._libtcod import ffi, lib
353+
import tcod.color # noqa: PLC0415
354+
from tcod._libtcod import ffi, lib # noqa: PLC0415
351355

352356
with Path("tcod/constants.py").open("w", encoding="utf-8") as f:
353357
all_names = []
@@ -441,6 +445,8 @@ def _fix_reserved_name(name: str) -> str:
441445

442446
@attrs.define(frozen=True)
443447
class ConvertedParam:
448+
"""Converted type parameter from C types into Python type-hints."""
449+
444450
name: str = attrs.field(converter=_fix_reserved_name)
445451
hint: str
446452
original: str
@@ -460,7 +466,8 @@ def _type_from_names(names: list[str]) -> str:
460466
return "Any"
461467

462468

463-
def _param_as_hint(node: pycparser.c_ast.Node, default_name: str) -> ConvertedParam:
469+
def _param_as_hint(node: pycparser.c_ast.Node, default_name: str) -> ConvertedParam: # noqa: PLR0911
470+
"""Return a Python type-hint from a C AST node."""
464471
original = pycparser.c_generator.CGenerator().visit(node)
465472
name: str
466473
names: list[str]

build_sdl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def check_sdl_version() -> None:
139139
sdl_version_str = subprocess.check_output(["sdl3-config", "--version"], universal_newlines=True).strip()
140140
except FileNotFoundError as exc:
141141
msg = (
142-
f"libsdl3-dev or equivalent must be installed on your system and must be at least version {needed_version}."
143-
"\nsdl3-config must be on PATH."
142+
f"libsdl3-dev or equivalent must be installed on your system and must be at least version {needed_version}.\n"
143+
"sdl3-config must be on PATH."
144144
)
145145
raise RuntimeError(msg) from exc
146146
except subprocess.CalledProcessError as exc:
@@ -223,8 +223,8 @@ def on_include_not_found(self, is_malformed: bool, is_system_include: bool, curd
223223
assert "SDL3/SDL" not in includepath, (includepath, curdir)
224224
raise pcpp.OutputDirective(pcpp.Action.IgnoreAndRemove)
225225

226-
def _should_track_define(self, tokens: list[Any]) -> bool:
227-
if len(tokens) < 3:
226+
def _should_track_define(self, tokens: list[Any]) -> bool: # noqa: PLR0911
227+
if len(tokens) < 3: # noqa: PLR2004
228228
return False
229229
if tokens[0].value in IGNORE_DEFINES:
230230
return False
@@ -236,7 +236,7 @@ def _should_track_define(self, tokens: list[Any]) -> bool:
236236
return False # Likely calls a private function.
237237
if tokens[1].type == "CPP_LPAREN":
238238
return False # Function-like macro.
239-
if len(tokens) >= 4 and tokens[2].type == "CPP_INTEGER" and tokens[3].type == "CPP_DOT":
239+
if len(tokens) >= 4 and tokens[2].type == "CPP_INTEGER" and tokens[3].type == "CPP_DOT": # noqa: PLR2004
240240
return False # Value is a floating point number.
241241
if tokens[0].value.startswith("SDL_PR") and (tokens[0].value.endswith("32") or tokens[0].value.endswith("64")):
242242
return False # Data type for printing, which is not needed.

examples/cavegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Any
1111

1212
import numpy as np
13-
import scipy.signal # type: ignore
13+
import scipy.signal # type: ignore[import-untyped]
1414
from numpy.typing import NDArray
1515

1616

tcod/color.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def __setitem__(self, index: Any, value: Any) -> None: # noqa: ANN401, D105
8989
else:
9090
super().__setitem__(index, value)
9191

92+
__hash__ = None
93+
9294
def __eq__(self, other: object) -> bool:
9395
"""Compare equality between colors.
9496

tcod/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import annotations
99

1010
import warnings
11-
from collections.abc import Iterable
1211
from pathlib import Path
1312
from typing import TYPE_CHECKING, Any, Literal, overload
1413

@@ -22,6 +21,7 @@
2221
from tcod.cffi import ffi, lib
2322

2423
if TYPE_CHECKING:
24+
from collections.abc import Iterable
2525
from os import PathLike
2626

2727
from numpy.typing import ArrayLike, NDArray

tcod/context.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
import pickle
3030
import sys
3131
import warnings
32-
from collections.abc import Iterable
3332
from pathlib import Path
34-
from typing import Any, Literal, NoReturn, TypeVar
33+
from typing import TYPE_CHECKING, Any, Literal, NoReturn, TypeVar
3534

3635
from typing_extensions import Self, deprecated
3736

@@ -44,6 +43,9 @@
4443
from tcod._internal import _check, _check_warn
4544
from tcod.cffi import ffi, lib
4645

46+
if TYPE_CHECKING:
47+
from collections.abc import Iterable
48+
4749
__all__ = (
4850
"RENDERER_OPENGL",
4951
"RENDERER_OPENGL2",

tcod/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def from_array(cls, array: ArrayLike) -> Image:
7171
.. versionadded:: 11.4
7272
"""
7373
array = np.asarray(array, dtype=np.uint8)
74-
height, width, depth = array.shape
74+
height, width, _depth = array.shape
7575
image = cls(width, height)
7676
image_array: NDArray[np.uint8] = np.asarray(image)
7777
image_array[...] = array

0 commit comments

Comments
 (0)