22
33from __future__ import annotations
44
5- import warnings
65from typing import (
76 TYPE_CHECKING ,
87 Any ,
2322
2423import attrs
2524from sentinel_value import sentinel
26- from typing_extensions import Self
25+ from typing_extensions import Self , deprecated
2726
2827import tcod .ecs .callbacks
2928import tcod .ecs .query
@@ -74,14 +73,13 @@ class Entity:
7473 """This entities unique identifier."""
7574
7675 @property
76+ @deprecated ("Use '.registry' instead of '.world'" )
7777 def world (self ) -> Registry :
7878 """Deprecated alias for registry.
7979
8080 .. deprecated:: 5.1
8181 Use :any:`registry` instead.
8282 """
83- if __debug__ :
84- warnings .warn ("Use '.registry' instead of '.world'" , DeprecationWarning , stacklevel = 2 )
8583 return self .registry
8684
8785 def __new__ (cls , registry : Registry , uid : object = object ) -> Entity : # noqa: PYI034
@@ -284,13 +282,13 @@ def relation_tag(self) -> EntityRelationsExclusive:
284282 return EntityRelationsExclusive (self , (IsA ,))
285283
286284 @property
285+ @deprecated ("The '.relation_tags' attribute has been renamed to '.relation_tag'" , category = FutureWarning )
287286 def relation_tags (self ) -> EntityRelationsExclusive :
288287 """Access an entities exclusive relations.
289288
290289 .. deprecated:: 3.2
291290 This attribute was renamed to :any:`relation_tag`.
292291 """
293- warnings .warn ("The '.relation_tags' attribute has been renamed to '.relation_tag'" , FutureWarning , stacklevel = 2 )
294292 return EntityRelationsExclusive (self , (IsA ,))
295293
296294 @property
@@ -303,12 +301,8 @@ def relation_tags_many(self) -> EntityRelations:
303301 """
304302 return EntityRelations (self , (IsA ,))
305303
306- def _set_name (self , value : object , stacklevel : int = 1 ) -> None :
307- warnings .warn (
308- "The name feature has been deprecated and will be removed." ,
309- FutureWarning ,
310- stacklevel = stacklevel + 1 ,
311- )
304+ @deprecated ("The name feature has been deprecated and will be removed." , category = FutureWarning )
305+ def _set_name (self , value : object ) -> None :
312306 old_name = self .name
313307 if old_name is not None : # Remove self from names
314308 del self .registry ._names_by_name [old_name ]
@@ -333,8 +327,9 @@ def name(self) -> object:
333327 return self .registry ._names_by_entity .get (self )
334328
335329 @name .setter
330+ @deprecated ("The name feature has been deprecated and will be removed." , category = FutureWarning )
336331 def name (self , value : object ) -> None :
337- self ._set_name (value , stacklevel = 2 )
332+ self ._set_name (value )
338333
339334 def __repr__ (self ) -> str :
340335 """Return a representation of this entity.
@@ -410,17 +405,13 @@ def __call__(self, *, traverse: Iterable[object]) -> Self:
410405 """
411406 return self .__class__ (self .entity , tuple (traverse ))
412407
413- def set (self , value : object , * , _stacklevel : int = 1 ) -> None :
408+ @deprecated ("Setting values without an explicit key has been deprecated." , category = FutureWarning )
409+ def set (self , value : object ) -> None :
414410 """Assign or overwrite a component, automatically deriving the key.
415411
416412 .. deprecated:: 3.1
417413 Setting values without an explicit key has been deprecated.
418414 """
419- warnings .warn (
420- "Setting values without an explicit key has been deprecated." ,
421- FutureWarning ,
422- stacklevel = _stacklevel + 1 ,
423- )
424415 key = value .__class__
425416 self [key ] = value
426417
@@ -498,15 +489,17 @@ def __len__(self) -> int:
498489 """Return the number of components belonging to this entity."""
499490 return len (self .keys ())
500491
501- def update_values (self , values : Iterable [object ], * , _stacklevel : int = 1 ) -> None :
492+ @deprecated ("Setting values without an explicit key has been deprecated." , category = FutureWarning )
493+ def update_values (self , values : Iterable [object ]) -> None :
502494 """Add or overwrite multiple components inplace, deriving the keys from the values.
503495
504496 .. deprecated:: 3.1
505497 Setting values without an explicit key has been deprecated.
506498 """
507499 for value in values :
508- self .set (value , _stacklevel = _stacklevel + 1 )
500+ self .set (value )
509501
502+ @deprecated ("This method has been deprecated. Iterate over items instead." , category = FutureWarning )
510503 def by_name_type (self , name_type : type [_T1 ], component_type : type [_T2 ]) -> Iterator [tuple [_T1 , type [_T2 ]]]:
511504 """Iterate over all of an entities component keys with a specific (name_type, component_type) combination.
512505
@@ -515,7 +508,6 @@ def by_name_type(self, name_type: type[_T1], component_type: type[_T2]) -> Itera
515508 .. deprecated:: 3.1
516509 This method has been deprecated. Iterate over items instead.
517510 """
518- warnings .warn ("This method has been deprecated. Iterate over items instead." , FutureWarning , stacklevel = 2 )
519511 # Naive implementation until I feel like optimizing it
520512 for key in self :
521513 if not isinstance (key , tuple ):
0 commit comments