Skip to content

Commit ebdd0e4

Browse files
committed
Resolve lint warnings
1 parent 05eda1c commit ebdd0e4

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

tcod/bsp.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727

2828
from __future__ import annotations
2929

30-
from collections.abc import Iterator
3130
from typing import TYPE_CHECKING, Any
3231

3332
from typing_extensions import deprecated
3433

3534
from tcod.cffi import ffi, lib
3635

3736
if TYPE_CHECKING:
37+
from collections.abc import Iterator
38+
3839
import tcod.random
3940

4041

@@ -125,7 +126,11 @@ def _unpack_bsp_tree(self, cdata: Any) -> None: # noqa: ANN401
125126
self.children[1].parent = self
126127
self.children[1]._unpack_bsp_tree(lib.TCOD_bsp_right(cdata))
127128

128-
def split_once(self, horizontal: bool, position: int) -> None:
129+
def split_once(
130+
self,
131+
horizontal: bool, # noqa: FBT001
132+
position: int,
133+
) -> None:
129134
"""Split this partition into 2 sub-partitions.
130135
131136
Args:
@@ -211,13 +216,13 @@ def level_order(self) -> Iterator[BSP]:
211216
212217
.. versionadded:: 8.3
213218
"""
214-
next = [self]
215-
while next:
216-
level = next
217-
next = []
219+
next_ = [self]
220+
while next_:
221+
level = next_
222+
next_ = []
218223
yield from level
219224
for node in level:
220-
next.extend(node.children)
225+
next_.extend(node.children)
221226

222227
def inverted_level_order(self) -> Iterator[BSP]:
223228
"""Iterate over this BSP's hierarchy in inverse level order.

tcod/random.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
import os
1313
import random
1414
import warnings
15-
from collections.abc import Hashable
16-
from typing import Any
15+
from typing import TYPE_CHECKING, Any
1716

1817
from typing_extensions import deprecated
1918

2019
import tcod.constants
2120
from tcod.cffi import ffi, lib
2221

22+
if TYPE_CHECKING:
23+
from collections.abc import Hashable
24+
2325
MERSENNE_TWISTER = tcod.constants.RNG_MT
2426
COMPLEMENTARY_MULTIPLY_WITH_CARRY = tcod.constants.RNG_CMWC
2527
MULTIPLY_WITH_CARRY = tcod.constants.RNG_CMWC

tests/test_tcod.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
from tcod import libtcodpy
1919

2020

21-
def raise_Exception(*_args: object) -> NoReturn:
21+
def raise_exception(*_args: object) -> NoReturn:
2222
raise RuntimeError("testing exception") # noqa: TRY003, EM101
2323

2424

2525
def test_line_error() -> None:
2626
"""Test exception propagation."""
2727
with pytest.raises(RuntimeError), pytest.warns():
28-
libtcodpy.line(0, 0, 10, 10, py_callback=raise_Exception)
28+
libtcodpy.line(0, 0, 10, 10, py_callback=raise_exception)
2929

3030

3131
@pytest.mark.filterwarnings("ignore:Iterate over nodes using")
@@ -39,7 +39,7 @@ def test_tcod_bsp() -> None:
3939
assert not bsp.children
4040

4141
with pytest.raises(RuntimeError):
42-
libtcodpy.bsp_traverse_pre_order(bsp, raise_Exception)
42+
libtcodpy.bsp_traverse_pre_order(bsp, raise_exception)
4343

4444
bsp.split_recursive(3, 4, 4, 1, 1)
4545
for node in bsp.walk():
@@ -102,7 +102,7 @@ def test_tcod_map_pickle() -> None:
102102
def test_tcod_map_pickle_fortran() -> None:
103103
map_ = tcod.map.Map(2, 3, order="F")
104104
map2: tcod.map.Map = pickle.loads(pickle.dumps(copy.copy(map_)))
105-
assert map_._Map__buffer.strides == map2._Map__buffer.strides # type: ignore
105+
assert map_._Map__buffer.strides == map2._Map__buffer.strides # type: ignore[attr-defined]
106106
assert map_.transparent.strides == map2.transparent.strides
107107
assert map_.walkable.strides == map2.walkable.strides
108108
assert map_.fov.strides == map2.fov.strides
@@ -148,7 +148,7 @@ def test_path_numpy(dtype: DTypeLike) -> None:
148148
tcod.path.AStar(np.ones((2, 2), dtype=np.float64))
149149

150150

151-
def path_cost(this_x: int, this_y: int, dest_x: int, dest_y: int) -> bool:
151+
def path_cost(_this_x: int, _this_y: int, _dest_x: int, _dest_y: int) -> bool:
152152
return True
153153

154154

@@ -160,7 +160,7 @@ def test_path_callback() -> None:
160160

161161

162162
def test_key_repr() -> None:
163-
Key = libtcodpy.Key
163+
Key = libtcodpy.Key # noqa: N806
164164
key = Key(vk=1, c=2, shift=True)
165165
assert key.vk == 1
166166
assert key.c == 2 # noqa: PLR2004
@@ -172,7 +172,7 @@ def test_key_repr() -> None:
172172

173173

174174
def test_mouse_repr() -> None:
175-
Mouse = libtcodpy.Mouse
175+
Mouse = libtcodpy.Mouse # noqa: N806
176176
mouse = Mouse(x=1, lbutton=True)
177177
mouse_copy = eval(repr(mouse)) # noqa: S307
178178
assert mouse.x == mouse_copy.x
@@ -185,22 +185,22 @@ def test_cffi_structs() -> None:
185185

186186

187187
@pytest.mark.filterwarnings("ignore")
188-
def test_recommended_size(console: tcod.console.Console) -> None:
188+
def test_recommended_size(console: tcod.console.Console) -> None: # noqa: ARG001
189189
tcod.console.recommended_size()
190190

191191

192192
@pytest.mark.filterwarnings("ignore")
193-
def test_context(uses_window: None) -> None:
193+
def test_context(uses_window: None) -> None: # noqa: ARG001
194194
with tcod.context.new_window(32, 32, renderer=libtcodpy.RENDERER_SDL2):
195195
pass
196-
WIDTH, HEIGHT = 16, 4
197-
with tcod.context.new_terminal(columns=WIDTH, rows=HEIGHT, renderer=libtcodpy.RENDERER_SDL2) as context:
196+
width, height = 16, 4
197+
with tcod.context.new_terminal(columns=width, rows=height, renderer=libtcodpy.RENDERER_SDL2) as context:
198198
console = tcod.console.Console(*context.recommended_console_size())
199199
context.present(console)
200200
assert context.sdl_window_p is not None
201201
assert context.renderer_type >= 0
202202
context.change_tileset(tcod.tileset.Tileset(16, 16))
203203
context.pixel_to_tile(0, 0)
204204
context.pixel_to_subtile(0, 0)
205-
with pytest.raises(RuntimeError, match=".*context has been closed"):
205+
with pytest.raises(RuntimeError, match=r".*context has been closed"):
206206
context.present(console)

0 commit comments

Comments
 (0)