1414import time
1515import warnings
1616from pathlib import Path
17- from typing import Any
17+ from typing import TYPE_CHECKING , Any
1818
1919import numpy as np
20- from numpy .typing import NDArray
2120
2221import tcod .cffi
2322import tcod .context
2928from tcod import libtcodpy
3029from tcod .sdl .video import WindowFlags
3130
31+ if TYPE_CHECKING :
32+ from numpy .typing import NDArray
33+
3234# ruff: noqa: S311
3335
3436if not sys .warnoptions :
@@ -96,13 +98,13 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
9698 libtcodpy .sys_save_screenshot ()
9799 print ("png" )
98100 elif event .sym == tcod .event .KeySym .ESCAPE :
99- raise SystemExit ()
101+ raise SystemExit
100102 elif event .sym in RENDERER_KEYS :
101103 # Swap the active context for one with a different renderer.
102104 init_context (RENDERER_KEYS [event .sym ])
103105
104106 def ev_quit (self , event : tcod .event .Quit ) -> None :
105- raise SystemExit ()
107+ raise SystemExit
106108
107109
108110class TrueColorSample (Sample ):
@@ -307,7 +309,7 @@ def on_draw(self) -> None:
307309 sample_console .print (
308310 2 ,
309311 2 ,
310- "%s (ENTER to change)" % self .FLAG_NAMES [self .bk_flag & 0xFF ],
312+ f" { self .FLAG_NAMES [self .bk_flag & 0xFF ]} (ENTER to change)" ,
311313 fg = WHITE ,
312314 bg = None ,
313315 )
@@ -431,26 +433,26 @@ def on_draw(self) -> None:
431433 sample_console .print (2 , 2 + cur_func , text , fg = WHITE , bg = LIGHT_BLUE )
432434 else :
433435 sample_console .print (2 , 2 + cur_func , text , fg = GREY , bg = None )
434- sample_console .print (2 , 11 , "Y/H : zoom (% 2.1f)" % self . zoom , fg = WHITE , bg = None )
436+ sample_console .print (2 , 11 , f "Y/H : zoom ({ self . zoom : 2.1f} )" , fg = WHITE , bg = None )
435437 if self .implementation != tcod .noise .Implementation .SIMPLE :
436438 sample_console .print (
437439 2 ,
438440 12 ,
439- "E/D : hurst (% 2.1f)" % self . hurst ,
441+ f "E/D : hurst ({ self . hurst : 2.1f} )" ,
440442 fg = WHITE ,
441443 bg = None ,
442444 )
443445 sample_console .print (
444446 2 ,
445447 13 ,
446- "R/F : lacunarity (% 2.1f)" % self . lacunarity ,
448+ f "R/F : lacunarity ({ self . lacunarity : 2.1f} )" ,
447449 fg = WHITE ,
448450 bg = None ,
449451 )
450452 sample_console .print (
451453 2 ,
452454 14 ,
453- "T/G : octaves (% 2.1f)" % self . octaves ,
455+ f "T/G : octaves ({ self . octaves : 2.1f} )" ,
454456 fg = WHITE ,
455457 bg = None ,
456458 )
@@ -991,7 +993,7 @@ def on_draw(self) -> None:
991993 walls = "OFF"
992994 if bsp_room_walls :
993995 walls = "ON"
994- sample_console .print (1 , 6 , "2 : room walls %s" % walls , fg = WHITE , bg = None )
996+ sample_console .print (1 , 6 , f "2 : room walls { walls } " , fg = WHITE , bg = None )
995997 # render the level
996998 for y in range (SAMPLE_SCREEN_HEIGHT ):
997999 for x in range (SAMPLE_SCREEN_WIDTH ):
@@ -1161,7 +1163,7 @@ def on_draw(self) -> None:
11611163 sample_console .print (
11621164 1 ,
11631165 1 ,
1164- "%s \n \n + : next generator\n - : prev generator" % self . sets [ self . current_set ] ,
1166+ f" { self . sets [ self . current_set ] } \n \n + : next generator\n - : prev generator" ,
11651167 fg = WHITE ,
11661168 bg = None ,
11671169 )
@@ -1214,8 +1216,8 @@ def ev_keydown(self, event: tcod.event.KeyDown) -> None:
12141216
12151217# the coordinates of all tiles in the screen, as numpy arrays.
12161218# example: (4x3 pixels screen)
1217- # xc = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
1218- # yc = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]
1219+ # xc = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]] # noqa: ERA001
1220+ # yc = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]] # noqa: ERA001
12191221if numpy_available :
12201222 (xc , yc ) = np .meshgrid (range (SCREEN_W ), range (SCREEN_H ))
12211223 # translate coordinates of all pixels to center
@@ -1504,7 +1506,7 @@ def handle_events() -> None:
15041506
15051507 SAMPLES [cur_sample ].dispatch (event )
15061508 if isinstance (event , tcod .event .Quit ):
1507- raise SystemExit ()
1509+ raise SystemExit
15081510
15091511
15101512def draw_samples_menu () -> None :
@@ -1518,7 +1520,7 @@ def draw_samples_menu() -> None:
15181520 root_console .print (
15191521 2 ,
15201522 46 - (len (SAMPLES ) - i ),
1521- " %s" % sample .name .ljust (19 ),
1523+ f " { sample .name .ljust (19 )} " ,
15221524 fg ,
15231525 bg ,
15241526 alignment = libtcodpy .LEFT ,
0 commit comments