Skip to content

Commit 233e4a7

Browse files
committed
Update deprecations to a more standard syntax
1 parent 4b25bc4 commit 233e4a7

File tree

7 files changed

+36
-41
lines changed

7 files changed

+36
-41
lines changed

tcod/bsp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929

3030
from typing import Any, Iterator
3131

32+
from typing_extensions import deprecated
33+
3234
import tcod.random
33-
from tcod._internal import deprecate
3435
from tcod.cffi import ffi, lib
3536

3637

@@ -72,7 +73,7 @@ def __init__(self, x: int, y: int, width: int, height: int) -> None:
7273
self.children: tuple[()] | tuple[BSP, BSP] = ()
7374

7475
@property
75-
@deprecate("This attribute has been renamed to `width`.", FutureWarning)
76+
@deprecated("This attribute has been renamed to `width`.", category=FutureWarning)
7677
def w(self) -> int: # noqa: D102
7778
return self.width
7879

@@ -81,7 +82,7 @@ def w(self, value: int) -> None:
8182
self.width = value
8283

8384
@property
84-
@deprecate("This attribute has been renamed to `height`.", FutureWarning)
85+
@deprecated("This attribute has been renamed to `height`.", category=FutureWarning)
8586
def h(self) -> int: # noqa: D102
8687
return self.height
8788

@@ -177,7 +178,7 @@ def split_recursive( # noqa: PLR0913
177178
)
178179
self._unpack_bsp_tree(cdata)
179180

180-
@deprecate("Use pre_order method instead of walk.")
181+
@deprecated("Use pre_order method instead of walk.")
181182
def walk(self) -> Iterator[BSP]:
182183
"""Iterate over this BSP's hierarchy in pre order.
183184

tcod/console.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import numpy as np
1616
from numpy.typing import ArrayLike, NDArray
17-
from typing_extensions import Literal
17+
from typing_extensions import Literal, deprecated
1818

1919
import tcod._internal
2020
import tcod.constants
21-
from tcod._internal import _check, _path_encode, deprecate
21+
from tcod._internal import _check, _path_encode
2222
from tcod.cffi import ffi, lib
2323

2424

@@ -248,7 +248,7 @@ def ch(self) -> NDArray[np.intc]:
248248
return self._tiles["ch"].T if self._order == "F" else self._tiles["ch"]
249249

250250
@property
251-
@deprecate("This attribute has been renamed to `rgba`.", category=FutureWarning)
251+
@deprecated("This attribute has been renamed to `rgba`.", category=FutureWarning)
252252
def tiles(self) -> NDArray[Any]:
253253
"""An array of this consoles raw tile data.
254254
@@ -264,7 +264,7 @@ def tiles(self) -> NDArray[Any]:
264264
return self.rgba
265265

266266
@property
267-
@deprecate("This attribute has been renamed to `rgba`.", category=FutureWarning)
267+
@deprecated("This attribute has been renamed to `rgba`.", category=FutureWarning)
268268
def buffer(self) -> NDArray[Any]:
269269
"""An array of this consoles raw tile data.
270270
@@ -276,7 +276,7 @@ def buffer(self) -> NDArray[Any]:
276276
return self.rgba
277277

278278
@property
279-
@deprecate("This attribute has been renamed to `rgb`.", category=FutureWarning)
279+
@deprecated("This attribute has been renamed to `rgb`.", category=FutureWarning)
280280
def tiles_rgb(self) -> NDArray[Any]:
281281
"""An array of this consoles data without the alpha channel.
282282
@@ -288,7 +288,7 @@ def tiles_rgb(self) -> NDArray[Any]:
288288
return self.rgb
289289

290290
@property
291-
@deprecate("This attribute has been renamed to `rgb`.", category=FutureWarning)
291+
@deprecated("This attribute has been renamed to `rgb`.", category=FutureWarning)
292292
def tiles2(self) -> NDArray[Any]:
293293
"""This name is deprecated in favour of :any:`rgb`.
294294
@@ -352,7 +352,7 @@ def default_bg(self) -> tuple[int, int, int]:
352352
return color.r, color.g, color.b
353353

354354
@default_bg.setter
355-
@deprecate("Console defaults have been deprecated.", category=FutureWarning)
355+
@deprecated("Console defaults have been deprecated.", category=FutureWarning)
356356
def default_bg(self, color: tuple[int, int, int]) -> None:
357357
self._console_data.back = color
358358

@@ -363,7 +363,7 @@ def default_fg(self) -> tuple[int, int, int]:
363363
return color.r, color.g, color.b
364364

365365
@default_fg.setter
366-
@deprecate("Console defaults have been deprecated.", category=FutureWarning)
366+
@deprecated("Console defaults have been deprecated.", category=FutureWarning)
367367
def default_fg(self, color: tuple[int, int, int]) -> None:
368368
self._console_data.fore = color
369369

@@ -373,7 +373,7 @@ def default_bg_blend(self) -> int:
373373
return self._console_data.bkgnd_flag # type: ignore
374374

375375
@default_bg_blend.setter
376-
@deprecate("Console defaults have been deprecated.", category=FutureWarning)
376+
@deprecated("Console defaults have been deprecated.", category=FutureWarning)
377377
def default_bg_blend(self, value: int) -> None:
378378
self._console_data.bkgnd_flag = value
379379

@@ -383,7 +383,7 @@ def default_alignment(self) -> int:
383383
return self._console_data.alignment # type: ignore
384384

385385
@default_alignment.setter
386-
@deprecate("Console defaults have been deprecated.", category=FutureWarning)
386+
@deprecated("Console defaults have been deprecated.", category=FutureWarning)
387387
def default_alignment(self, value: int) -> None:
388388
self._console_data.alignment = value
389389

@@ -830,7 +830,7 @@ def blit( # noqa: PLR0913
830830
bg_alpha,
831831
)
832832

833-
@deprecate("Pass the key color to Console.blit instead of calling this function.")
833+
@deprecated("Pass the key color to Console.blit instead of calling this function.")
834834
def set_key_color(self, color: tuple[int, int, int] | None) -> None:
835835
"""Set a consoles blit transparent color.
836836
@@ -1234,7 +1234,7 @@ def get_height_rect(width: int, string: str) -> int:
12341234
return int(lib.TCOD_console_get_height_rect_wn(width, len(string_), string_))
12351235

12361236

1237-
@deprecate("This function does not support contexts.", category=FutureWarning)
1237+
@deprecated("This function does not support contexts.", category=FutureWarning)
12381238
def recommended_size() -> tuple[int, int]:
12391239
"""Return the recommended size of a console for the current active window.
12401240

tcod/context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
from pathlib import Path
3333
from typing import Any, Iterable, NoReturn, TypeVar
3434

35-
from typing_extensions import Literal
35+
from typing_extensions import Literal, deprecated
3636

3737
import tcod.console
3838
import tcod.event
3939
import tcod.render
4040
import tcod.sdl.render
4141
import tcod.sdl.video
4242
import tcod.tileset
43-
from tcod._internal import _check, _check_warn, pending_deprecate
43+
from tcod._internal import _check, _check_warn
4444
from tcod.cffi import ffi, lib
4545

4646
__all__ = (
@@ -574,7 +574,7 @@ def new( # noqa: PLR0913
574574
return Context._claim(context_pp[0])
575575

576576

577-
@pending_deprecate("Call tcod.context.new with width and height as keyword parameters.")
577+
@deprecated("Call tcod.context.new with width and height as keyword parameters.")
578578
def new_window( # noqa: PLR0913
579579
width: int,
580580
height: int,
@@ -601,7 +601,7 @@ def new_window( # noqa: PLR0913
601601
)
602602

603603

604-
@pending_deprecate("Call tcod.context.new with columns and rows as keyword parameters.")
604+
@deprecated("Call tcod.context.new with columns and rows as keyword parameters.")
605605
def new_terminal( # noqa: PLR0913
606606
columns: int,
607607
rows: int,

tcod/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import numpy as np
1919
from numpy.typing import ArrayLike, NDArray
20+
from typing_extensions import deprecated
2021

2122
import tcod.console
22-
from tcod._internal import _console, _path_encode, deprecate
23+
from tcod._internal import _console, _path_encode
2324
from tcod.cffi import ffi, lib
2425

2526

@@ -357,10 +358,9 @@ def _get_format_name(format: int) -> str:
357358
return str(format)
358359

359360

360-
@deprecate(
361+
@deprecated(
361362
"This function may be removed in the future."
362363
" It's recommended to load images with a more complete image library such as python-Pillow or python-imageio.",
363-
category=PendingDeprecationWarning,
364364
)
365365
def load(filename: str | PathLike[str]) -> NDArray[np.uint8]:
366366
"""Load a PNG file as an RGBA array.

tcod/libtcodpy.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import numpy as np
1414
from numpy.typing import NDArray
15-
from typing_extensions import Literal
15+
from typing_extensions import Literal, deprecated
1616

1717
import tcod.bsp
1818
import tcod.console
@@ -77,6 +77,7 @@ def BKGND_ADDALPHA(a: int) -> int:
7777
return BKGND_ADDA | (int(a * 255) << 8)
7878

7979

80+
@deprecated("Console array attributes perform better than this class.")
8081
class ConsoleBuffer:
8182
"""Simple console that allows direct (fast) access to cells. Simplifies use of the "fill" functions.
8283
@@ -111,11 +112,6 @@ def __init__(
111112
112113
Values to fill the buffer are optional, defaults to black with no characters.
113114
"""
114-
warnings.warn(
115-
"Console array attributes perform better than this class.",
116-
DeprecationWarning,
117-
stacklevel=2,
118-
)
119115
self.width = width
120116
self.height = height
121117
self.clear(back_r, back_g, back_b, fore_r, fore_g, fore_b, char)
@@ -271,6 +267,7 @@ def blit(
271267
dest.ch.ravel()[:] = self.char
272268

273269

270+
@deprecated("Using this class is not recommended.")
274271
class Dice(_CDataWrapper):
275272
"""A libtcod dice object.
276273
@@ -286,11 +283,6 @@ class Dice(_CDataWrapper):
286283
"""
287284

288285
def __init__(self, *args: Any, **kwargs: Any) -> None:
289-
warnings.warn(
290-
"Using this class is not recommended.",
291-
DeprecationWarning,
292-
stacklevel=2,
293-
)
294286
super().__init__(*args, **kwargs)
295287
if self.cdata == ffi.NULL:
296288
self._init(*args, **kwargs)

tcod/random.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import warnings
1515
from typing import Any, Hashable
1616

17+
from typing_extensions import deprecated
18+
1719
import tcod.constants
18-
from tcod._internal import deprecate
1920
from tcod.cffi import ffi, lib
2021

2122
MERSENNE_TWISTER = tcod.constants.RNG_MT
@@ -127,7 +128,7 @@ def gauss(self, mu: float, sigma: float) -> float:
127128
"""
128129
return float(lib.TCOD_random_get_gaussian_double(self.random_c, mu, sigma))
129130

130-
@deprecate("This is a typo, rename this to 'gauss'", category=FutureWarning)
131+
@deprecated("This is a typo, rename this to 'gauss'", category=FutureWarning)
131132
def guass(self, mu: float, sigma: float) -> float: # noqa: D102
132133
return self.gauss(mu, sigma)
133134

@@ -146,7 +147,7 @@ def inverse_gauss(self, mu: float, sigma: float) -> float:
146147
"""
147148
return float(lib.TCOD_random_get_gaussian_double_inv(self.random_c, mu, sigma))
148149

149-
@deprecate("This is a typo, rename this to 'inverse_gauss'", category=FutureWarning)
150+
@deprecated("This is a typo, rename this to 'inverse_gauss'", category=FutureWarning)
150151
def inverse_guass(self, mu: float, sigma: float) -> float: # noqa: D102
151152
return self.inverse_gauss(mu, sigma)
152153

tcod/tileset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
import numpy as np
2222
from numpy.typing import ArrayLike, NDArray
23+
from typing_extensions import deprecated
2324

2425
import tcod.console
25-
from tcod._internal import _check, _check_p, _console, _path_encode, _raise_tcod_error, deprecate
26+
from tcod._internal import _check, _check_p, _console, _path_encode, _raise_tcod_error
2627
from tcod.cffi import ffi, lib
2728

2829

@@ -235,7 +236,7 @@ def remap(self, codepoint: int, x: int, y: int = 0) -> None:
235236
)
236237

237238

238-
@deprecate("Using the default tileset is deprecated.")
239+
@deprecated("Using the default tileset is deprecated.")
239240
def get_default() -> Tileset:
240241
"""Return a reference to the default Tileset.
241242
@@ -248,7 +249,7 @@ def get_default() -> Tileset:
248249
return Tileset._claim(lib.TCOD_get_default_tileset())
249250

250251

251-
@deprecate("Using the default tileset is deprecated.")
252+
@deprecated("Using the default tileset is deprecated.")
252253
def set_default(tileset: Tileset) -> None:
253254
"""Set the default tileset.
254255
@@ -278,7 +279,7 @@ def load_truetype_font(path: str | PathLike[str], tile_width: int, tile_height:
278279
return Tileset._claim(cdata)
279280

280281

281-
@deprecate("Accessing the default tileset is deprecated.")
282+
@deprecated("Accessing the default tileset is deprecated.")
282283
def set_truetype_font(path: str | PathLike[str], tile_width: int, tile_height: int) -> None:
283284
"""Set the default tileset from a `.ttf` or `.otf` file.
284285

0 commit comments

Comments
 (0)