1515
1616import attrs
1717from sentinel_value import sentinel
18- from typing_extensions import Self , deprecated
18+ from typing_extensions import Self , TypeForm , deprecated
1919
2020import tcod .ecs .callbacks
2121import tcod .ecs .query
@@ -382,7 +382,7 @@ def _traverse_entities(start: Entity, traverse_parents: tuple[object, ...]) -> I
382382
383383
384384@attrs .define (eq = False , frozen = True , weakref_slot = False )
385- class EntityComponents (MutableMapping [type [Any ] | tuple [object , type [Any ]], object ]):
385+ class EntityComponents (MutableMapping [TypeForm [Any ] | tuple [object , TypeForm [Any ]], object ]):
386386 """A proxy attribute to access an entities components like a dictionary.
387387
388388 See :any:`Entity.components`.
@@ -440,7 +440,7 @@ def __setitem__(self, key: ComponentKey[T], value: T) -> None:
440440
441441 tcod .ecs .callbacks ._on_component_changed (key , self .entity , old_value , value )
442442
443- def __delitem__ (self , key : type [object ] | tuple [object , type [object ]]) -> None :
443+ def __delitem__ (self , key : TypeForm [object ] | tuple [object , TypeForm [object ]]) -> None :
444444 """Delete a directly held component from an entity."""
445445 assert self .__assert_key (key )
446446
@@ -467,8 +467,8 @@ def keys(self) -> AbstractSet[ComponentKey[object]]: # type: ignore[override]
467467 * (_components_by_entity .get (entity , ()) for entity in _traverse_entities (self .entity , self .traverse ))
468468 )
469469
470- def __contains__ (self , key : ComponentKey [ object ] ) -> bool : # type: ignore[override]
471- """Return True if this entity has the provided component."""
470+ def __contains__ (self , key : object ) -> bool :
471+ """Return True if this entity has the provided component key ."""
472472 _components_by_entity = self .entity .registry ._components_by_entity
473473 return any (
474474 key in _components_by_entity .get (entity , ()) for entity in _traverse_entities (self .entity , self .traverse )
@@ -493,21 +493,20 @@ def update_values(self, values: Iterable[object]) -> None:
493493 self .set (value )
494494
495495 @deprecated ("This method has been deprecated. Iterate over items instead." , category = FutureWarning )
496- def by_name_type (self , name_type : type [_T1 ], component_type : type [_T2 ]) -> Iterator [tuple [_T1 , type [_T2 ]]]:
496+ def by_name_type (self , name_type : type [_T1 ], component_type : TypeForm [_T2 ]) -> Iterator [tuple [_T1 , TypeForm [_T2 ]]]:
497497 """Iterate over all of an entities component keys with a specific (name_type, component_type) combination.
498498
499499 .. versionadded:: 3.0
500500
501501 .. deprecated:: 3.1
502502 This method has been deprecated. Iterate over items instead.
503503 """
504- # Naive implementation until I feel like optimizing it
505504 for key in self :
506505 if not isinstance (key , tuple ):
507506 continue
508507 key_name , key_component = key
509508 if key_component is component_type and isinstance (key_name , name_type ):
510- yield key_name , key_component
509+ yield key_name , key_component # type: ignore[unused-ignore] # Too complex for PyLance, deprecated anyways
511510
512511 @overload
513512 def __ior__ (self , value : SupportsKeysAndGetItem [ComponentKey [Any ], Any ]) -> Self : ...
@@ -1044,14 +1043,14 @@ def __getitem__(self, key: ComponentKey[T]) -> EntityComponentRelationMapping[T]
10441043 """Access relations for this component key as a `{target: component}` dict-like object."""
10451044 return EntityComponentRelationMapping (self .entity , key , self .traverse )
10461045
1047- def __setitem__ (self , __key : ComponentKey [T ], __values : Mapping [Entity , object ], / ) -> None :
1046+ def __setitem__ (self , __key : ComponentKey [T ], __values : Mapping [Entity , T ], / ) -> None :
10481047 """Redefine the component relations for this entity.
10491048
10501049 ..versionadded:: 4.2.0
10511050 """
10521051 if isinstance (__values , EntityComponentRelationMapping ) and __values .entity is self .entity :
10531052 return
1054- mapping : EntityComponentRelationMapping [object ] = self [__key ]
1053+ mapping : EntityComponentRelationMapping [T ] = self [__key ]
10551054 mapping .clear ()
10561055 for target , component in __values .items ():
10571056 mapping [target ] = component
0 commit comments