3030 [ 92, 35, 33, 71, 90],
3131 [ 76, 54, 85, 144, 164],
3232 [ 63, 94, 159, 209, 203]], dtype=uint8)
33- """ # noqa: E501
33+ """
3434from __future__ import annotations
3535
3636import enum
3737import warnings
38- from typing import Any , List , Optional , Sequence , Tuple , Union
38+ from typing import Any , Sequence
3939
4040import numpy as np
4141from numpy .typing import ArrayLike , NDArray
4242from typing_extensions import Literal
4343
4444import tcod .constants
4545import tcod .random
46- from tcod ._internal import deprecate
4746from tcod .loader import ffi , lib
4847
4948
@@ -92,14 +91,15 @@ def __getattr__(name: str) -> Implementation:
9291 if name in Implementation .__members__ :
9392 warnings .warn (
9493 f"'tcod.noise.{ name } ' is deprecated," f" use 'tcod.noise.Implementation.{ name } ' instead." ,
95- DeprecationWarning ,
94+ FutureWarning ,
9695 stacklevel = 2 ,
9796 )
9897 return Implementation [name ]
99- raise AttributeError (f"module { __name__ } has no attribute { name } " )
98+ msg = f"module { __name__ } has no attribute { name } "
99+ raise AttributeError (msg )
100100
101101
102- class Noise ( object ) :
102+ class Noise :
103103 """A configurable noise sampler.
104104
105105 The ``hurst`` exponent describes the raggedness of the resultant noise,
@@ -130,10 +130,11 @@ def __init__(
130130 hurst : float = 0.5 ,
131131 lacunarity : float = 2.0 ,
132132 octaves : float = 4 ,
133- seed : Optional [ Union [ int , tcod .random .Random ]] = None ,
134- ):
133+ seed : int | tcod .random .Random | None = None ,
134+ ) -> None :
135135 if not 0 < dimensions <= 4 :
136- raise ValueError ("dimensions must be in range 0 < n <= 4, got %r" % (dimensions ,))
136+ msg = f"dimensions must be in range 0 < n <= 4, got { dimensions } "
137+ raise ValueError (msg )
137138 self ._seed = seed
138139 self ._random = self .__rng_from_seed (seed )
139140 _random_c = self ._random .random_c
@@ -149,7 +150,7 @@ def __init__(
149150 self .implementation = implementation # sanity check
150151
151152 @staticmethod
152- def __rng_from_seed (seed : Union [ None , int , tcod .random .Random ] ) -> tcod .random .Random :
153+ def __rng_from_seed (seed : None | int | tcod .random .Random ) -> tcod .random .Random :
153154 if seed is None or isinstance (seed , int ):
154155 return tcod .random .Random (seed = seed , algorithm = tcod .random .MERSENNE_TWISTER )
155156 return seed
@@ -174,11 +175,6 @@ def __repr__(self) -> str:
174175 def dimensions (self ) -> int :
175176 return int (self ._tdl_noise_c .dimensions )
176177
177- @property
178- @deprecate ("This is a misspelling of 'dimensions'." , FutureWarning )
179- def dimentions (self ) -> int :
180- return self .dimensions
181-
182178 @property
183179 def algorithm (self ) -> int :
184180 noise_type = self .noise_c .noise_type
@@ -195,7 +191,8 @@ def implementation(self) -> int:
195191 @implementation .setter
196192 def implementation (self , value : int ) -> None :
197193 if not 0 <= value < 3 :
198- raise ValueError ("%r is not a valid implementation. " % (value ,))
194+ msg = f"{ value !r} is not a valid implementation. "
195+ raise ValueError (msg )
199196 self ._tdl_noise_c .implementation = value
200197
201198 @property
@@ -242,7 +239,8 @@ def __getitem__(self, indexes: Any) -> NDArray[np.float32]:
242239 c_input = [ffi .NULL , ffi .NULL , ffi .NULL , ffi .NULL ]
243240 for i , index in enumerate (indexes ):
244241 if index .dtype .type == np .object_ :
245- raise TypeError ("Index arrays can not be of dtype np.object_." )
242+ msg = "Index arrays can not be of dtype np.object_."
243+ raise TypeError (msg )
246244 indexes [i ] = np .ascontiguousarray (index , dtype = np .float32 )
247245 c_input [i ] = ffi .from_buffer ("float*" , indexes [i ])
248246
@@ -296,12 +294,12 @@ def sample_mgrid(self, mgrid: ArrayLike) -> NDArray[np.float32]:
296294 """
297295 mgrid = np .ascontiguousarray (mgrid , np .float32 )
298296 if mgrid .shape [0 ] != self .dimensions :
299- raise ValueError (
300- "mgrid.shape[0] must equal self.dimensions, " "%r[0] != %r" % (mgrid .shape , self .dimensions )
301- )
297+ msg = f"mgrid.shape[0] must equal self.dimensions, { mgrid .shape !r} [0] != { self .dimensions !r} "
298+ raise ValueError (msg )
302299 out : np .ndarray [Any , np .dtype [np .float32 ]] = np .ndarray (mgrid .shape [1 :], np .float32 )
303300 if mgrid .shape [1 :] != out .shape :
304- raise ValueError ("mgrid.shape[1:] must equal out.shape, " "%r[1:] != %r" % (mgrid .shape , out .shape ))
301+ msg = f"mgrid.shape[1:] must equal out.shape, { mgrid .shape !r} [1:] != { out .shape !r} "
302+ raise ValueError (msg )
305303 lib .NoiseSampleMeshGrid (
306304 self ._tdl_noise_c ,
307305 out .size ,
@@ -323,8 +321,9 @@ def sample_ogrid(self, ogrid: Sequence[ArrayLike]) -> NDArray[np.float32]:
323321 The ``dtype`` is `numpy.float32`.
324322 """
325323 if len (ogrid ) != self .dimensions :
326- raise ValueError ("len(ogrid) must equal self.dimensions, " "%r != %r" % (len (ogrid ), self .dimensions ))
327- ogrids : List [NDArray [np .float32 ]] = [np .ascontiguousarray (array , np .float32 ) for array in ogrid ]
324+ msg = f"len(ogrid) must equal self.dimensions, { len (ogrid )!r} != { self .dimensions !r} "
325+ raise ValueError (msg )
326+ ogrids : list [NDArray [np .float32 ]] = [np .ascontiguousarray (array , np .float32 ) for array in ogrid ]
328327 out : np .ndarray [Any , np .dtype [np .float32 ]] = np .ndarray ([array .size for array in ogrids ], np .float32 )
329328 lib .NoiseSampleOpenMeshGrid (
330329 self ._tdl_noise_c ,
@@ -335,7 +334,7 @@ def sample_ogrid(self, ogrid: Sequence[ArrayLike]) -> NDArray[np.float32]:
335334 )
336335 return out
337336
338- def __getstate__ (self ) -> Any :
337+ def __getstate__ (self ) -> dict [ str , Any ] :
339338 state = self .__dict__ .copy ()
340339 if self .dimensions < 4 and self .noise_c .waveletTileData == ffi .NULL :
341340 # Trigger a side effect of wavelet, so that copies will be synced.
@@ -366,7 +365,7 @@ def __getstate__(self) -> Any:
366365 }
367366 return state
368367
369- def __setstate__ (self , state : Any ) -> None :
368+ def __setstate__ (self , state : dict [ str , Any ] ) -> None :
370369 if isinstance (state , tuple ): # deprecated format
371370 return self ._setstate_old (state )
372371 # unpack wavelet tile data if it exists
@@ -384,6 +383,7 @@ def __setstate__(self, state: Any) -> None:
384383 state ["_tdl_noise_c" ]["noise" ] = state ["noise_c" ]
385384 state ["_tdl_noise_c" ] = ffi .new ("TDLNoise*" , state ["_tdl_noise_c" ])
386385 self .__dict__ .update (state )
386+ return None
387387
388388 def _setstate_old (self , state : Any ) -> None :
389389 self ._random = state [0 ]
@@ -403,11 +403,11 @@ def _setstate_old(self, state: Any) -> None:
403403
404404
405405def grid (
406- shape : Tuple [int , ...],
407- scale : Union [ Tuple [ float , ...], float ] ,
408- origin : Optional [ Tuple [ int , ...]] = None ,
406+ shape : tuple [int , ...],
407+ scale : tuple [ float , ...] | float ,
408+ origin : tuple [ int , ...] | None = None ,
409409 indexing : Literal ["ij" , "xy" ] = "xy" ,
410- ) -> Tuple [NDArray [Any ], ...]:
410+ ) -> tuple [NDArray [Any ], ...]:
411411 """Generate a mesh-grid of sample points to use with noise sampling.
412412
413413 Args:
@@ -444,14 +444,16 @@ def grid(
444444 dtype=float32)
445445
446446 .. versionadded:: 12.2
447- """ # noqa: E501
447+ """
448448 if isinstance (scale , float ):
449449 scale = (scale ,) * len (shape )
450450 if origin is None :
451451 origin = (0 ,) * len (shape )
452452 if len (shape ) != len (scale ):
453- raise TypeError ("shape must have the same length as scale" )
453+ msg = "shape must have the same length as scale"
454+ raise TypeError (msg )
454455 if len (shape ) != len (origin ):
455- raise TypeError ("shape must have the same length as origin" )
456+ msg = "shape must have the same length as origin"
457+ raise TypeError (msg )
456458 indexes = (np .arange (i_shape ) * i_scale + i_origin for i_shape , i_scale , i_origin in zip (shape , scale , origin ))
457459 return tuple (np .meshgrid (* indexes , copy = False , sparse = True , indexing = indexing ))
0 commit comments