77import warnings
88from typing import TYPE_CHECKING , Any , AnyStr , Callable , NoReturn , SupportsInt , TypeVar
99
10- import numpy as np
1110from typing_extensions import Literal , LiteralString , deprecated
1211
1312from tcod .cffi import ffi , lib
1615 from pathlib import Path
1716 from types import TracebackType
1817
19- from numpy .typing import ArrayLike , NDArray
20-
21- import tcod .image
2218
2319FuncType = Callable [..., Any ]
2420F = TypeVar ("F" , bound = FuncType )
2521T = TypeVar ("T" )
2622
2723
2824def _deprecate_passthrough (
29- message : str , / , * , category : type [Warning ] = DeprecationWarning , stacklevel : int = 0
25+ message : str , # noqa: ARG001
26+ / ,
27+ * ,
28+ category : type [Warning ] = DeprecationWarning , # noqa: ARG001
29+ stacklevel : int = 0 , # noqa: ARG001
3030) -> Callable [[F ], F ]:
3131 """Return a decorator which skips wrapping a warning onto functions. This is used for non-debug runs."""
3232
@@ -51,7 +51,7 @@ def pending_deprecate(
5151
5252def verify_order (order : Literal ["C" , "F" ]) -> Literal ["C" , "F" ]:
5353 """Verify and return a Numpy order string."""
54- order = order .upper () # type: ignore
54+ order = order .upper () # type: ignore[assignment]
5555 if order not in ("C" , "F" ):
5656 msg = f"order must be 'C' or 'F', not { order !r} "
5757 raise TypeError (msg )
@@ -91,7 +91,7 @@ def _check_warn(error: int, stacklevel: int = 2) -> int:
9191def _unpack_char_p (char_p : Any ) -> str : # noqa: ANN401
9292 if char_p == ffi .NULL :
9393 return ""
94- return ffi .string (char_p ). decode () # type: ignore
94+ return str ( ffi .string (char_p ), encoding = "utf-8" )
9595
9696
9797def _int (int_or_str : SupportsInt | str | bytes ) -> int :
@@ -171,7 +171,7 @@ def __enter__(self) -> Callable[[Any], None]:
171171 return self .propagate
172172
173173 def __exit__ (
174- self , type : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
174+ self , _type : type [BaseException ] | None , value : BaseException | None , traceback : TracebackType | None
175175 ) -> None :
176176 """If we're holding on to an exception, raise it now.
177177
@@ -232,42 +232,3 @@ def _console(console: Any) -> Any: # noqa: ANN401
232232 stacklevel = 3 ,
233233 )
234234 return ffi .NULL
235-
236-
237- class TempImage :
238- """An Image-like container for NumPy arrays."""
239-
240- def __init__ (self , array : ArrayLike ) -> None :
241- """Initialize an image from the given array. May copy or reference the array."""
242- self ._array : NDArray [np .uint8 ] = np .ascontiguousarray (array , dtype = np .uint8 )
243- height , width , depth = self ._array .shape
244- if depth != 3 : # noqa: PLR2004
245- msg = f"Array must have RGB channels. Shape is: { self ._array .shape !r} "
246- raise TypeError (msg )
247- self ._buffer = ffi .from_buffer ("TCOD_color_t[]" , self ._array )
248- self ._mipmaps = ffi .new (
249- "struct TCOD_mipmap_*" ,
250- {
251- "width" : width ,
252- "height" : height ,
253- "fwidth" : width ,
254- "fheight" : height ,
255- "buf" : self ._buffer ,
256- "dirty" : True ,
257- },
258- )
259- self .image_c = ffi .new (
260- "TCOD_Image*" ,
261- {
262- "nb_mipmaps" : 1 ,
263- "mipmaps" : self ._mipmaps ,
264- "has_key_color" : False ,
265- },
266- )
267-
268-
269- def _as_image (image : ArrayLike | tcod .image .Image ) -> TempImage | tcod .image .Image :
270- """Convert this input into an Image-like object."""
271- if hasattr (image , "image_c" ):
272- return image
273- return TempImage (image )
0 commit comments