Skip to content

Commit 95e605a

Browse files
committed
Fix or ignore several Ruff issues
1 parent d841fe7 commit 95e605a

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

build_libtcod.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
import sys
1111
from pathlib import Path
12-
from typing import Any, Iterable, Iterator
12+
from typing import Any, ClassVar, Iterable, Iterator
1313

1414
from cffi import FFI
1515

@@ -45,7 +45,7 @@ class ParsedHeader:
4545
"""
4646

4747
# Class dictionary of all parsed headers.
48-
all_headers: dict[Path, ParsedHeader] = {}
48+
all_headers: ClassVar[dict[Path, ParsedHeader]] = {}
4949

5050
def __init__(self, path: Path) -> None:
5151
"""Initialize and organize a header file."""

examples/termbox/termbox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
[ ] not all keys/events are mapped
1616
"""
1717

18+
# ruff: noqa
19+
1820

1921
class TermboxException(Exception):
2022
def __init__(self, msg) -> None:

examples/termbox/termboxtest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
import termbox
44

5+
# ruff: noqa
6+
57
spaceord = ord(" ")
68

79

examples/thread_jobs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,32 @@
3131
REPEAT = 10 # Number to times to run a test. Only the fastest result is shown.
3232

3333

34-
def test_fov(map_: tcod.map.Map) -> tcod.map.Map:
34+
def test_fov(map_: tcod.map.Map) -> tcod.map.Map: # noqa: D103
3535
map_.compute_fov(MAP_WIDTH // 2, MAP_HEIGHT // 2)
3636
return map_
3737

3838

39-
def test_fov_single(maps: List[tcod.map.Map]) -> None:
39+
def test_fov_single(maps: List[tcod.map.Map]) -> None: # noqa: D103
4040
for map_ in maps:
4141
test_fov(map_)
4242

4343

44-
def test_fov_threads(executor: concurrent.futures.Executor, maps: List[tcod.map.Map]) -> None:
44+
def test_fov_threads(executor: concurrent.futures.Executor, maps: List[tcod.map.Map]) -> None: # noqa: D103
4545
for _result in executor.map(test_fov, maps):
4646
pass
4747

4848

49-
def test_astar(map_: tcod.map.Map) -> List[Tuple[int, int]]:
49+
def test_astar(map_: tcod.map.Map) -> List[Tuple[int, int]]: # noqa: D103
5050
astar = tcod.path.AStar(map_)
5151
return astar.get_path(0, 0, MAP_WIDTH - 1, MAP_HEIGHT - 1)
5252

5353

54-
def test_astar_single(maps: List[tcod.map.Map]) -> None:
54+
def test_astar_single(maps: List[tcod.map.Map]) -> None: # noqa: D103
5555
for map_ in maps:
5656
test_astar(map_)
5757

5858

59-
def test_astar_threads(executor: concurrent.futures.Executor, maps: List[tcod.map.Map]) -> None:
59+
def test_astar_threads(executor: concurrent.futures.Executor, maps: List[tcod.map.Map]) -> None: # noqa: D103
6060
for _result in executor.map(test_astar, maps):
6161
pass
6262

tcod/color.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Color(List[int]):
1717
b (int): Blue value, from 0 to 255.
1818
"""
1919

20-
def __init__(self, r: int = 0, g: int = 0, b: int = 0) -> None:
20+
def __init__(self, r: int = 0, g: int = 0, b: int = 0) -> None: # noqa: D107
2121
list.__setitem__(self, slice(None), (r & 0xFF, g & 0xFF, b & 0xFF))
2222

2323
@property
@@ -82,13 +82,13 @@ def __getitem__(self, index: Any) -> Any: # noqa: ANN401
8282
return super().__getitem__(index)
8383

8484
@deprecate("This class will not be mutable in the future.", FutureWarning)
85-
def __setitem__(self, index: Any, value: Any) -> None: # noqa: ANN401
85+
def __setitem__(self, index: Any, value: Any) -> None: # noqa: ANN401, D105
8686
if isinstance(index, str):
8787
super().__setitem__("rgb".index(index), value)
8888
else:
8989
super().__setitem__(index, value)
9090

91-
def __eq__(self, other: Any) -> bool:
91+
def __eq__(self, other: object) -> bool:
9292
"""Compare equality between colors.
9393
9494
Also compares with standard sequences such as 3-item tuples or lists.
@@ -99,7 +99,7 @@ def __eq__(self, other: Any) -> bool:
9999
return False
100100

101101
@deprecate("Use NumPy instead for color math operations.", FutureWarning)
102-
def __add__(self, other: Any) -> Color: # type: ignore[override]
102+
def __add__(self, other: object) -> Color: # type: ignore[override]
103103
"""Add two colors together.
104104
105105
.. deprecated:: 9.2
@@ -108,7 +108,7 @@ def __add__(self, other: Any) -> Color: # type: ignore[override]
108108
return Color._new_from_cdata(lib.TCOD_color_add(self, other))
109109

110110
@deprecate("Use NumPy instead for color math operations.", FutureWarning)
111-
def __sub__(self, other: Any) -> Color:
111+
def __sub__(self, other: object) -> Color:
112112
"""Subtract one color from another.
113113
114114
.. deprecated:: 9.2
@@ -117,7 +117,7 @@ def __sub__(self, other: Any) -> Color:
117117
return Color._new_from_cdata(lib.TCOD_color_subtract(self, other))
118118

119119
@deprecate("Use NumPy instead for color math operations.", FutureWarning)
120-
def __mul__(self, other: Any) -> Color:
120+
def __mul__(self, other: object) -> Color:
121121
"""Multiply with a scaler or another color.
122122
123123
.. deprecated:: 9.2

tcod/libtcodpy.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
)
5555

5656
# Functions are too deprecated to make changes.
57-
# ruff: noqa: ANN401 PLR0913
57+
# ruff: noqa: ANN401 PLR0913 D102 D103 D105 D107
5858

5959
Bsp = tcod.bsp.BSP
6060

@@ -1477,6 +1477,9 @@ def console_print_ex(
14771477
con (Console): Any Console instance.
14781478
x (int): Character x position from the left.
14791479
y (int): Character y position from the top.
1480+
flag: Blending mode to use.
1481+
alignment: The libtcod alignment constant.
1482+
fmt: A unicode or bytes string, optionally using color codes.
14801483
14811484
.. deprecated:: 8.5
14821485
Use :any:`Console.print_` instead.
@@ -1726,8 +1729,7 @@ def console_wait_for_keypress(flush: bool) -> Key:
17261729
"""Block until the user presses a key, then returns a new Key.
17271730
17281731
Args:
1729-
flush bool: If True then the event queue is cleared before waiting
1730-
for the next event.
1732+
flush: If True then the event queue is cleared before waiting for the next event.
17311733
17321734
Returns:
17331735
Key: A new Key instance.
@@ -2136,8 +2138,8 @@ def path_new_using_function(
21362138
Args:
21372139
w (int): Clipping width.
21382140
h (int): Clipping height.
2139-
func (Callable[[int, int, int, int, Any], float]):
2140-
userData (Any):
2141+
func: Callback function with the format: `f(origin_x, origin_y, dest_x, dest_y, userData) -> float`
2142+
userData (Any): An object passed to the callback.
21412143
dcost (float): A multiplier for the cost of diagonal movement.
21422144
Can be set to 0 to disable diagonal movement.
21432145
@@ -2485,6 +2487,7 @@ def heightmap_copy(hm1: NDArray[np.float32], hm2: NDArray[np.float32]) -> None:
24852487
"""Copy the heightmap ``hm1`` to ``hm2``.
24862488
24872489
Args:
2490+
hm: A numpy.ndarray formatted for heightmap functions.
24882491
hm1 (numpy.ndarray): The source heightmap.
24892492
hm2 (numpy.ndarray): The destination heightmap.
24902493
@@ -2499,6 +2502,7 @@ def heightmap_normalize(hm: NDArray[np.float32], mi: float = 0.0, ma: float = 1.
24992502
"""Normalize heightmap values between ``mi`` and ``ma``.
25002503
25012504
Args:
2505+
hm: A numpy.ndarray formatted for heightmap functions.
25022506
mi (float): The lowest value after normalization.
25032507
ma (float): The highest value after normalization.
25042508
"""
@@ -2944,7 +2948,7 @@ def heightmap_has_land_on_border(hm: NDArray[np.float32], waterlevel: float) ->
29442948
29452949
Args:
29462950
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
2947-
waterLevel (float): The water level to use.
2951+
waterlevel (float): The water level to use.
29482952
29492953
Returns:
29502954
bool: True if the map edges are below ``waterlevel``, otherwise False.
@@ -3493,6 +3497,7 @@ def noise_set_type(n: tcod.noise.Noise, typ: int) -> None:
34933497
"""Set a Noise objects default noise algorithm.
34943498
34953499
Args:
3500+
n: Noise object.
34963501
typ (int): Any NOISE_* constant.
34973502
"""
34983503
n.algorithm = typ
@@ -3531,7 +3536,7 @@ def noise_get_fbm(
35313536
n (Noise): A Noise instance.
35323537
f (Sequence[float]): The point to sample the noise from.
35333538
typ (int): The noise algorithm to use.
3534-
octaves (float): The level of level. Should be more than 1.
3539+
oc (float): The level of level. Should be more than 1.
35353540
35363541
Returns:
35373542
float: The sampled noise value.
@@ -3552,7 +3557,7 @@ def noise_get_turbulence(
35523557
n (Noise): A Noise instance.
35533558
f (Sequence[float]): The point to sample the noise from.
35543559
typ (int): The noise algorithm to use.
3555-
octaves (float): The level of level. Should be more than 1.
3560+
oc (float): The level of level. Should be more than 1.
35563561
35573562
Returns:
35583563
float: The sampled noise value.
@@ -3781,8 +3786,8 @@ def random_get_int(rnd: tcod.random.Random | None, mi: int, ma: int) -> int:
37813786
37823787
Args:
37833788
rnd (Optional[Random]): A Random instance, or None to use the default.
3784-
low (int): The lower bound of the random range, inclusive.
3785-
high (int): The upper bound of the random range, inclusive.
3789+
mi (int): The lower bound of the random range, inclusive.
3790+
ma (int): The upper bound of the random range, inclusive.
37863791
37873792
Returns:
37883793
int: A random integer in the range ``mi`` <= n <= ``ma``.
@@ -3798,8 +3803,8 @@ def random_get_float(rnd: tcod.random.Random | None, mi: float, ma: float) -> fl
37983803
37993804
Args:
38003805
rnd (Optional[Random]): A Random instance, or None to use the default.
3801-
low (float): The lower bound of the random range, inclusive.
3802-
high (float): The upper bound of the random range, inclusive.
3806+
mi (float): The lower bound of the random range, inclusive.
3807+
ma (float): The upper bound of the random range, inclusive.
38033808
38043809
Returns:
38053810
float: A random double precision float
@@ -3827,8 +3832,8 @@ def random_get_int_mean(rnd: tcod.random.Random | None, mi: int, ma: int, mean:
38273832
38283833
Args:
38293834
rnd (Optional[Random]): A Random instance, or None to use the default.
3830-
low (int): The lower bound of the random range, inclusive.
3831-
high (int): The upper bound of the random range, inclusive.
3835+
mi (int): The lower bound of the random range, inclusive.
3836+
ma (int): The upper bound of the random range, inclusive.
38323837
mean (int): The mean return value.
38333838
38343839
Returns:
@@ -3845,8 +3850,8 @@ def random_get_float_mean(rnd: tcod.random.Random | None, mi: float, ma: float,
38453850
38463851
Args:
38473852
rnd (Optional[Random]): A Random instance, or None to use the default.
3848-
low (float): The lower bound of the random range, inclusive.
3849-
high (float): The upper bound of the random range, inclusive.
3853+
mi (float): The lower bound of the random range, inclusive.
3854+
ma (float): The upper bound of the random range, inclusive.
38503855
mean (float): The mean return value.
38513856
38523857
Returns:
@@ -4071,7 +4076,7 @@ def sys_save_screenshot(name: str | PathLike[str] | None = None) -> None:
40714076
screenshot000.png, screenshot001.png, etc. Whichever is available first.
40724077
40734078
Args:
4074-
file Optional[AnyStr]: File path to save screenshot.
4079+
name: File path to save screenshot.
40754080
40764081
.. deprecated:: 11.13
40774082
This function is not supported by contexts.
@@ -4179,8 +4184,7 @@ def sys_register_SDL_renderer(callback: Callable[[Any], None]) -> None:
41794184
The callback is called on every call to :any:`libtcodpy.console_flush`.
41804185
41814186
Args:
4182-
callback Callable[[CData], None]:
4183-
A function which takes a single argument.
4187+
callback: A function which takes a single argument.
41844188
41854189
.. deprecated:: 11.13
41864190
This function is not supported by contexts.

0 commit comments

Comments
 (0)