Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# extract vars required by behaviors
# can handle partials as well
all_required_vars = set(sum((
b.required_vars if not isinstance(b, partial)
else b.func.required_vars
for b in behaviors
), []))
missing = [var for var in all_required_vars
if var not in state_vars]
if missing:
raise MissingVarError('required vars {} are missing in agent `state_vars`'.format(missing))
return type.__new__(cls, name, parents, dct)
class Agent(aiomas.Agent, metaclass=AgentMeta):
state_vars = []
behaviors = []
def __init__(self, container, state, *args, world_addr=None, **kwargs):
super().__init__(container)
self.state = self.State(**state)
self.world_addr = world_addr
self._updates = []
self.init(state, *args, **kwargs)
def init(self, state, *args, **kwargs):
"""initialization for an agent. you should
override this method instead of `__init__`."""
pass
async def emit(self, name, *args, **kwargs):