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
@@ -173,7 +174,7 @@ class Texture:
173174 Create a new texture using :any:`Renderer.new_texture` or :any:`Renderer.upload_texture`.
174175 """
175176
176- def __init__ (self , sdl_texture_p : Any , sdl_renderer_p : Any = None ) -> None :
177+ def __init__ (self , sdl_texture_p : Any , sdl_renderer_p : Any = None ) -> None : # noqa: ANN401
177178 """Encapsulate an SDL_Texture pointer. This function is private."""
178179 self .p = sdl_texture_p
179180 self ._sdl_renderer_p = sdl_renderer_p # Keep alive.
@@ -200,6 +201,10 @@ def __eq__(self, other: object) -> bool:
200201 return bool (self .p == other .p )
201202 return NotImplemented
202203
204+ def __hash__ (self ) -> int :
205+ """Return hash for the owned pointer."""
206+ return hash (self .p )
207+
203208 def update (self , pixels : NDArray [Any ], rect : tuple [int , int , int , int ] | None = None ) -> None :
204209 """Update the pixel data of this texture.
205210
@@ -267,7 +272,7 @@ def __exit__(self, *_: object) -> None:
267272class Renderer :
268273 """SDL Renderer."""
269274
270- def __init__ (self , sdl_renderer_p : Any ) -> None :
275+ def __init__ (self , sdl_renderer_p : Any ) -> None : # noqa: ANN401
271276 """Encapsulate an SDL_Renderer pointer. This function is private."""
272277 if ffi .typeof (sdl_renderer_p ) is not ffi .typeof ("struct SDL_Renderer*" ):
273278 msg = f"Expected a { ffi .typeof ('struct SDL_Window*' )} type (was { ffi .typeof (sdl_renderer_p )} )."
@@ -283,6 +288,10 @@ def __eq__(self, other: object) -> bool:
283288 return bool (self .p == other .p )
284289 return NotImplemented
285290
291+ def __hash__ (self ) -> int :
292+ """Return hash for the owned pointer."""
293+ return hash (self .p )
294+
286295 def copy ( # noqa: PLR0913
287296 self ,
288297 texture : Texture ,
@@ -328,7 +337,7 @@ def set_render_target(self, texture: Texture) -> _RestoreTargetContext:
328337 _check (lib .SDL_SetRenderTarget (self .p , texture .p ))
329338 return restore
330339
331- def new_texture (self , width : int , height : int , * , format : int | None = None , access : int | None = None ) -> Texture :
340+ def new_texture (self , width : int , height : int , * , format : int | None = None , access : int | None = None ) -> Texture : # noqa: A002
332341 """Allocate and return a new Texture for this renderer.
333342
334343 Args:
@@ -339,13 +348,13 @@ def new_texture(self, width: int, height: int, *, format: int | None = None, acc
339348 See :any:`TextureAccess` for more options.
340349 """
341350 if format is None :
342- format = 0
351+ format = 0 # noqa: A001
343352 if access is None :
344353 access = int (lib .SDL_TEXTUREACCESS_STATIC )
345354 texture_p = ffi .gc (lib .SDL_CreateTexture (self .p , format , access , width , height ), lib .SDL_DestroyTexture )
346355 return Texture (texture_p , self .p )
347356
348- def upload_texture (self , pixels : NDArray [Any ], * , format : int | None = None , access : int | None = None ) -> Texture :
357+ def upload_texture (self , pixels : NDArray [Any ], * , format : int | None = None , access : int | None = None ) -> Texture : # noqa: A002
349358 """Return a new Texture from an array of pixels.
350359
351360 Args:
@@ -358,9 +367,9 @@ def upload_texture(self, pixels: NDArray[Any], *, format: int | None = None, acc
358367 assert len (pixels .shape ) == 3 # noqa: PLR2004
359368 assert pixels .dtype == np .uint8
360369 if pixels .shape [2 ] == 4 : # noqa: PLR2004
361- format = int (lib .SDL_PIXELFORMAT_RGBA32 )
370+ format = int (lib .SDL_PIXELFORMAT_RGBA32 ) # noqa: A001
362371 elif pixels .shape [2 ] == 3 : # noqa: PLR2004
363- format = int (lib .SDL_PIXELFORMAT_RGB24 )
372+ format = int (lib .SDL_PIXELFORMAT_RGB24 ) # noqa: A001
364373 else :
365374 msg = f"Can't determine the format required for an array of shape { pixels .shape } ."
366375 raise TypeError (msg )
@@ -502,7 +511,7 @@ def viewport(self) -> tuple[int, int, int, int] | None:
502511 def viewport (self , rect : tuple [int , int , int , int ] | None ) -> None :
503512 _check (lib .SDL_SetRenderViewport (self .p , (rect ,)))
504513
505- def set_vsync (self , enable : bool ) -> None :
514+ def set_vsync (self , enable : bool ) -> None : # noqa: FBT001
506515 """Enable or disable VSync for this renderer.
507516
508517 .. versionadded:: 13.5
@@ -625,7 +634,7 @@ def fill_rects(self, rects: NDArray[np.number] | Sequence[tuple[float, float, fl
625634 .. versionadded:: 13.5
626635 """
627636 rects = self ._convert_array (rects , item_length = 4 )
628- _check (lib .SDL_RenderFillRects (self .p , tcod . ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
637+ _check (lib .SDL_RenderFillRects (self .p , ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
629638
630639 def draw_rects (self , rects : NDArray [np .number ] | Sequence [tuple [float , float , float , float ]]) -> None :
631640 """Draw multiple outlined rectangles from an array.
@@ -638,7 +647,7 @@ def draw_rects(self, rects: NDArray[np.number] | Sequence[tuple[float, float, fl
638647 rects = self ._convert_array (rects , item_length = 4 )
639648 assert len (rects .shape ) == 2 # noqa: PLR2004
640649 assert rects .shape [1 ] == 4 # noqa: PLR2004
641- _check (lib .SDL_RenderRects (self .p , tcod . ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
650+ _check (lib .SDL_RenderRects (self .p , ffi .from_buffer ("SDL_FRect*" , rects ), rects .shape [0 ]))
642651
643652 def draw_points (self , points : NDArray [np .number ] | Sequence [tuple [float , float ]]) -> None :
644653 """Draw an array of points.
@@ -649,7 +658,7 @@ def draw_points(self, points: NDArray[np.number] | Sequence[tuple[float, float]]
649658 .. versionadded:: 13.5
650659 """
651660 points = self ._convert_array (points , item_length = 2 )
652- _check (lib .SDL_RenderPoints (self .p , tcod . ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
661+ _check (lib .SDL_RenderPoints (self .p , ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
653662
654663 def draw_lines (self , points : NDArray [np .number ] | Sequence [tuple [float , float ]]) -> None :
655664 """Draw a connected series of lines from an array.
@@ -660,7 +669,7 @@ def draw_lines(self, points: NDArray[np.number] | Sequence[tuple[float, float]])
660669 .. versionadded:: 13.5
661670 """
662671 points = self ._convert_array (points , item_length = 2 )
663- _check (lib .SDL_RenderLines (self .p , tcod . ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
672+ _check (lib .SDL_RenderLines (self .p , ffi .from_buffer ("SDL_FPoint*" , points ), points .shape [0 ]))
664673
665674 def geometry (
666675 self ,
0 commit comments