66from __future__ import annotations
77
88import enum
9- from collections .abc import Sequence
109from typing import TYPE_CHECKING , Any , Final , Literal
1110
1211import numpy as np
1817from tcod .sdl ._internal import Properties , _check , _check_p
1918
2019if TYPE_CHECKING :
20+ from collections .abc import Sequence
21+
2122 from numpy .typing import NDArray
2223
2324
@@ -186,7 +187,7 @@ class Texture:
186187 Create a new texture using :any:`Renderer.new_texture` or :any:`Renderer.upload_texture`.
187188 """
188189
189- def __init__ (self , sdl_texture_p : Any , sdl_renderer_p : Any = None ) -> None :
190+ def __init__ (self , sdl_texture_p : Any , sdl_renderer_p : Any = None ) -> None : # noqa: ANN401
190191 """Encapsulate an SDL_Texture pointer. This function is private."""
191192 self .p = sdl_texture_p
192193 self ._sdl_renderer_p = sdl_renderer_p # Keep alive.
@@ -213,6 +214,10 @@ def __eq__(self, other: object) -> bool:
213214 return bool (self .p == other .p )
214215 return NotImplemented
215216
217+ def __hash__ (self ) -> int :
218+ """Return hash for the owned pointer."""
219+ return hash (self .p )
220+
216221 def update (self , pixels : NDArray [Any ], rect : tuple [int , int , int , int ] | None = None ) -> None :
217222 """Update the pixel data of this texture.
218223
@@ -294,7 +299,7 @@ def __exit__(self, *_: object) -> None:
294299class Renderer :
295300 """SDL Renderer."""
296301
297- def __init__ (self , sdl_renderer_p : Any ) -> None :
302+ def __init__ (self , sdl_renderer_p : Any ) -> None : # noqa: ANN401
298303 """Encapsulate an SDL_Renderer pointer. This function is private."""
299304 if ffi .typeof (sdl_renderer_p ) is not ffi .typeof ("struct SDL_Renderer*" ):
300305 msg = f"Expected a { ffi .typeof ('struct SDL_Window*' )} type (was { ffi .typeof (sdl_renderer_p )} )."
@@ -310,6 +315,10 @@ def __eq__(self, other: object) -> bool:
310315 return bool (self .p == other .p )
311316 return NotImplemented
312317
318+ def __hash__ (self ) -> int :
319+ """Return hash for the owned pointer."""
320+ return hash (self .p )
321+
313322 def copy ( # noqa: PLR0913
314323 self ,
315324 texture : Texture ,
@@ -355,7 +364,7 @@ def set_render_target(self, texture: Texture) -> _RestoreTargetContext:
355364 _check (lib .SDL_SetRenderTarget (self .p , texture .p ))
356365 return restore
357366
358- def new_texture (self , width : int , height : int , * , format : int | None = None , access : int | None = None ) -> Texture :
367+ def new_texture (self , width : int , height : int , * , format : int | None = None , access : int | None = None ) -> Texture : # noqa: A002
359368 """Allocate and return a new Texture for this renderer.
360369
361370 Args:
@@ -366,13 +375,13 @@ def new_texture(self, width: int, height: int, *, format: int | None = None, acc
366375 See :any:`TextureAccess` for more options.
367376 """
368377 if format is None :
369- format = 0
378+ format = 0 # noqa: A001
370379 if access is None :
371380 access = int (lib .SDL_TEXTUREACCESS_STATIC )
372381 texture_p = ffi .gc (lib .SDL_CreateTexture (self .p , format , access , width , height ), lib .SDL_DestroyTexture )
373382 return Texture (texture_p , self .p )
374383
375- def upload_texture (self , pixels : NDArray [Any ], * , format : int | None = None , access : int | None = None ) -> Texture :
384+ def upload_texture (self , pixels : NDArray [Any ], * , format : int | None = None , access : int | None = None ) -> Texture : # noqa: A002
376385 """Return a new Texture from an array of pixels.
377386
378387 Args:
@@ -385,9 +394,9 @@ def upload_texture(self, pixels: NDArray[Any], *, format: int | None = None, acc
385394 assert len (pixels .shape ) == 3 # noqa: PLR2004
386395 assert pixels .dtype == np .uint8
387396 if pixels .shape [2 ] == 4 : # noqa: PLR2004
388- format = int (lib .SDL_PIXELFORMAT_RGBA32 )
397+ format = int (lib .SDL_PIXELFORMAT_RGBA32 ) # noqa: A001
389398 elif pixels .shape [2 ] == 3 : # noqa: PLR2004
390- format = int (lib .SDL_PIXELFORMAT_RGB24 )
399+ format = int (lib .SDL_PIXELFORMAT_RGB24 ) # noqa: A001
391400 else :
392401 msg = f"Can't determine the format required for an array of shape { pixels .shape } ."
393402 raise TypeError (msg )
@@ -529,7 +538,7 @@ def viewport(self) -> tuple[int, int, int, int] | None:
529538 def viewport (self , rect : tuple [int , int , int , int ] | None ) -> None :
530539 _check (lib .SDL_SetRenderViewport (self .p , (rect ,)))
531540
532- def set_vsync (self , enable : bool ) -> None :
541+ def set_vsync (self , enable : bool ) -> None : # noqa: FBT001
533542 """Enable or disable VSync for this renderer.
534543
535544 .. versionadded:: 13.5
@@ -652,7 +661,7 @@ def fill_rects(self, rects: NDArray[np.number] | Sequence[tuple[float, float, fl
652661 .. versionadded:: 13.5
653662 """
654663 rects = self ._convert_array (rects , item_length = 4 )
655- _check (lib .SDL_RenderFillRects (self .p , tcod . ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
664+ _check (lib .SDL_RenderFillRects (self .p , ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
656665
657666 def draw_rects (self , rects : NDArray [np .number ] | Sequence [tuple [float , float , float , float ]]) -> None :
658667 """Draw multiple outlined rectangles from an array.
@@ -665,7 +674,7 @@ def draw_rects(self, rects: NDArray[np.number] | Sequence[tuple[float, float, fl
665674 rects = self ._convert_array (rects , item_length = 4 )
666675 assert len (rects .shape ) == 2 # noqa: PLR2004
667676 assert rects .shape [1 ] == 4 # noqa: PLR2004
668- _check (lib .SDL_RenderRects (self .p , tcod . ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
677+ _check (lib .SDL_RenderRects (self .p , ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
669678
670679 def draw_points (self , points : NDArray [np .number ] | Sequence [tuple [float , float ]]) -> None :
671680 """Draw an array of points.
@@ -676,7 +685,7 @@ def draw_points(self, points: NDArray[np.number] | Sequence[tuple[float, float]]
676685 .. versionadded:: 13.5
677686 """
678687 points = self ._convert_array (points , item_length = 2 )
679- _check (lib .SDL_RenderPoints (self .p , tcod . ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
688+ _check (lib .SDL_RenderPoints (self .p , ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
680689
681690 def draw_lines (self , points : NDArray [np .number ] | Sequence [tuple [float , float ]]) -> None :
682691 """Draw a connected series of lines from an array.
@@ -687,7 +696,7 @@ def draw_lines(self, points: NDArray[np.number] | Sequence[tuple[float, float]])
687696 .. versionadded:: 13.5
688697 """
689698 points = self ._convert_array (points , item_length = 2 )
690- _check (lib .SDL_RenderLines (self .p , tcod . ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
699+ _check (lib .SDL_RenderLines (self .p , ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
691700
692701 def geometry (
693702 self ,
0 commit comments