33from __future__ import annotations
44
55import warnings
6- from collections .abc import Set
76from typing import (
87 TYPE_CHECKING ,
98 Any ,
3130from tcod .ecs .typing import ComponentKey
3231
3332if TYPE_CHECKING :
33+ from collections .abc import Set as AbstractSet
34+
3435 from _typeshed import SupportsKeysAndGetItem
3536
3637 from tcod .ecs .registry import Registry
@@ -80,7 +81,7 @@ def world(self) -> Registry:
8081 warnings .warn ("Use '.registry' instead of '.world'" , DeprecationWarning , stacklevel = 2 )
8182 return self .registry
8283
83- def __new__ (cls , registry : Registry , uid : object = object ) -> Entity :
84+ def __new__ (cls , registry : Registry , uid : object = object ) -> Entity : # noqa: PYI034
8485 """Return a unique entity for the given `registry` and `uid`.
8586
8687 If an entity already exists with a matching `registry` and `uid` then that entity is returned.
@@ -334,7 +335,7 @@ def __repr__(self) -> str:
334335 >>> registry["foo"]
335336 <Entity(uid='foo')>
336337 """
337- uid_str = f"object at 0x{ id (self .uid ):X} " if self .uid .__class__ == object else repr (self .uid )
338+ uid_str = f"object at 0x{ id (self .uid ):X} " if self .uid .__class__ is object else repr (self .uid )
338339 items = [f"{ self .__class__ .__name__ } (uid={ uid_str } )" ]
339340 name = self .name
340341 if name is not None : # Switch to older style
@@ -426,7 +427,7 @@ def __getitem__(self, key: ComponentKey[T]) -> T:
426427 for entity in _traverse_entities (self .entity , self .traverse ):
427428 try :
428429 return _components_by_entity [entity ][key ] # type: ignore[no-any-return]
429- except KeyError :
430+ except KeyError : # noqa: PERF203
430431 pass
431432 raise KeyError (key )
432433
@@ -461,7 +462,7 @@ def __delitem__(self, key: type[object] | tuple[object, type[object]]) -> None:
461462 tcod .ecs .query ._touch_component (self .entity .registry , key ) # Component removed
462463 tcod .ecs .callbacks ._on_component_changed (key , self .entity , old_value , None )
463464
464- def keys (self ) -> Set [ComponentKey [object ]]: # type: ignore[override]
465+ def keys (self ) -> AbstractSet [ComponentKey [object ]]: # type: ignore[override]
465466 """Return the components held by this entity, including inherited components."""
466467 _components_by_entity = self .entity .registry ._components_by_entity
467468 if not self .traverse :
@@ -611,7 +612,7 @@ def __len__(self) -> int:
611612 """Return the number of tags this entity has."""
612613 return len (self ._as_set ())
613614
614- def __ior__ (self , other : Set [object ]) -> Self :
615+ def __ior__ (self , other : AbstractSet [object ]) -> Self :
615616 """Add tags in-place.
616617
617618 .. versionadded:: 3.3
@@ -620,7 +621,7 @@ def __ior__(self, other: Set[object]) -> Self:
620621 self .add (to_add )
621622 return self
622623
623- def __isub__ (self , other : Set [Any ]) -> Self :
624+ def __isub__ (self , other : AbstractSet [Any ]) -> Self :
624625 """Remove tags in-place.
625626
626627 .. versionadded:: 3.3
@@ -787,10 +788,10 @@ def __delitem__(self, key: object) -> None:
787788 def __iter__ (self ) -> Iterator [Any ]:
788789 """Iterate over the unique relation tags of this entity."""
789790 _relation_tags_by_entity = self .entity .registry ._relation_tags_by_entity
790- EMPTY_DICT : dict [object , set [Entity ]] = {}
791+ empty_dict : dict [object , set [Entity ]] = {}
791792 yield from set ().union (
792793 * (
793- _relation_tags_by_entity .get (entity , EMPTY_DICT ).keys ()
794+ _relation_tags_by_entity .get (entity , empty_dict ).keys ()
794795 for entity in _traverse_entities (self .entity , self .traverse )
795796 )
796797 )
@@ -925,7 +926,7 @@ def __delitem__(self, target: Entity) -> None:
925926
926927 _relations_lookup_discard (registry , self .entity , self .key , target )
927928
928- def keys (self ) -> Set [Entity ]: # type: ignore[override]
929+ def keys (self ) -> AbstractSet [Entity ]: # type: ignore[override]
929930 """Return all entities with an associated component value."""
930931 _relation_components_by_entity = self .entity .registry ._relation_components_by_entity
931932 result : set [Entity ] = set ()
@@ -1003,7 +1004,7 @@ def clear(self) -> None:
10031004 for component_key in list (self .entity .registry ._relation_components_by_entity .get (self .entity , ())):
10041005 self [component_key ].clear ()
10051006
1006- def keys (self ) -> Set [ComponentKey [object ]]: # type: ignore[override]
1007+ def keys (self ) -> AbstractSet [ComponentKey [object ]]: # type: ignore[override]
10071008 """Returns the components keys this entity has relations for."""
10081009 _relation_components_by_entity = self .entity .registry ._relation_components_by_entity
10091010 return set ().union (
0 commit comments