Resolved some warnings and style issues

This commit is contained in:
Steffen Illium
2023-11-10 09:29:54 +01:00
parent a9462a8b6f
commit 6711a0976b
64 changed files with 331 additions and 361 deletions

View File

@@ -1,15 +1,15 @@
from collections import defaultdict
from typing import List
from typing import List, Iterator, Union
import numpy as np
from marl_factory_grid.environment.entity.object import _Object
from marl_factory_grid.environment.entity.object import Object
import marl_factory_grid.environment.constants as c
from marl_factory_grid.utils import helpers as h
class _Objects:
_entity = _Object
class Objects:
_entity = Object
@property
def var_can_be_bound(self):
@@ -50,7 +50,7 @@ class _Objects:
def __len__(self):
return len(self._data)
def __iter__(self):
def __iter__(self) -> Iterator[Union[Object, None]]:
return iter(self.values())
def add_item(self, item: _entity):
@@ -130,13 +130,14 @@ class _Objects:
repr_dict = {key: val for key, val in self._data.items() if key not in [c.WALLS]}
return f'{self.__class__.__name__}[{repr_dict}]'
def notify_del_entity(self, entity: _Object):
def notify_del_entity(self, entity: Object):
try:
# noinspection PyUnresolvedReferences
self.pos_dict[entity.pos].remove(entity)
except (AttributeError, ValueError, IndexError):
pass
def notify_add_entity(self, entity: _Object):
def notify_add_entity(self, entity: Object):
try:
if self not in entity.observers:
entity.add_observer(self)