Skip to content

Commit cad57bd

Browse files
committed
refactor: Replace Any with specific types in agent_info and tactics_agent classes for improved type safety
1 parent 8f5ec0b commit cad57bd

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

adf_core_python/core/agent/info/agent_info.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from time import time
4-
from typing import TYPE_CHECKING, Any
4+
from typing import TYPE_CHECKING
55

66
from rcrs_core.commands.Command import Command
77
from rcrs_core.entities.civilian import Civilian
@@ -18,13 +18,12 @@
1818

1919

2020
class AgentInfo:
21-
# TODO: Replace Any with the actual type
2221
def __init__(self, agent: Agent, world_model: WorldModel):
2322
self._agent: Agent = agent
2423
self._world_model: WorldModel = world_model
2524
self._time: int = 0
2625
self._action_history: dict[int, Action] = {}
27-
self._heard_commands: list[Any] = []
26+
self._heard_commands: list[Command] = []
2827
self._change_set: ChangeSet = ChangeSet()
2928
self._start_think_time: float = 0.0
3029

adf_core_python/core/agent/info/world_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def __init__(self, world_model: WorldModel):
1717
self._rollback: dict[EntityID, dict[int, dict[int, Any]]] = {}
1818
self._change_set: ChangeSet
1919

20-
# TODO: Implement the worldmodel access methods
2120
def get_world_model(self) -> WorldModel:
2221
"""
2322
Get the world model

adf_core_python/core/component/tactics/tactics_agent.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import time
44
from abc import ABC, abstractmethod
5-
from typing import TYPE_CHECKING, Any, Optional
5+
from typing import TYPE_CHECKING, Optional
66

7+
from adf_core_python.core.component.centralized.command_executor import CommandExecutor
78
from adf_core_python.core.logger.logger import get_agent_logger
89

910
if TYPE_CHECKING:
@@ -24,7 +25,7 @@ def __init__(self, parent: Optional[TacticsAgent] = None) -> None:
2425
self._parent = parent
2526
self._modules: list[AbstractModule] = []
2627
self._actions: list[ExtendAction] = []
27-
self._command_executor: Any = None
28+
self._command_executor: list[CommandExecutor] = []
2829

2930
@abstractmethod
3031
def initialize(
@@ -107,27 +108,27 @@ def register_action(self, action: ExtendAction) -> None:
107108
def unregister_action(self, action: ExtendAction) -> None:
108109
self._actions.remove(action)
109110

110-
def register_command_executor(self, command_executor: Any) -> None:
111-
self._command_executor = command_executor
111+
def register_command_executor(self, command_executor: CommandExecutor) -> None:
112+
self._command_executor.append(command_executor)
112113

113-
def unregister_command_executor(self) -> None:
114-
self._command_executor = None
114+
def unregister_command_executor(self, command_executor: CommandExecutor) -> None:
115+
self._command_executor.remove(command_executor)
115116

116117
def module_precompute(self, precompute_data: PrecomputeData) -> None:
117118
for module in self._modules:
118119
module.precompute(precompute_data)
119120
for action in self._actions:
120121
action.precompute(precompute_data)
121-
# for executor in self._command_executor:
122-
# executor.precompute(precompute_data)
122+
for executor in self._command_executor:
123+
executor.precompute(precompute_data)
123124

124125
def module_resume(self, precompute_data: PrecomputeData) -> None:
125126
for module in self._modules:
126127
module.resume(precompute_data)
127128
for action in self._actions:
128129
action.resume(precompute_data)
129-
# for executor in self._command_executor:
130-
# executor.resume(precompute_data)
130+
for executor in self._command_executor:
131+
executor.resume(precompute_data)
131132

132133
def module_prepare(self) -> None:
133134
for module in self._modules:
@@ -142,16 +143,16 @@ def module_prepare(self) -> None:
142143
self._logger.debug(
143144
f"module {action.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
144145
)
145-
# for executor in self._command_executor:
146-
# executor.prepare()
146+
for executor in self._command_executor:
147+
executor.prepare()
147148

148149
def module_update_info(self, message_manager: MessageManager) -> None:
149150
for module in self._modules:
150151
module.update_info(message_manager)
151152
for action in self._actions:
152153
action.update_info(message_manager)
153-
# for executor in self._command_executor:
154-
# executor.update_info(message_manager)
154+
for executor in self._command_executor:
155+
executor.update_info(message_manager)
155156

156157
def reset_count(self) -> None:
157158
for module in self._modules:
@@ -164,5 +165,8 @@ def reset_count(self) -> None:
164165
action.reset_count_resume()
165166
action.reset_count_prepare()
166167
action.reset_count_update_info()
167-
# for executor in self._command_executor:
168-
# executor.reset_count()
168+
for executor in self._command_executor:
169+
executor.reset_count_precompute()
170+
executor.reset_count_resume()
171+
executor.reset_count_prepare()
172+
executor.reset_count_update_info()

adf_core_python/core/logger/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def configure_logger() -> None:
7272
handler_stdout.setLevel(logging.INFO)
7373

7474
handler_file = RotatingFileHandler(
75-
"agent.log", maxBytes=10 * 1024 * 1024, backupCount=5
75+
"agent.log", maxBytes=1024 * 1024 * 1024, backupCount=5
7676
)
7777
handler_file.doRollover()
7878
handler_file.setFormatter(

adf_core_python/implement/action/default_extend_action_transport.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from adf_core_python.core.logger.logger import get_agent_logger
2525

2626

27-
# TODO: refactor this class
2827
class DefaultExtendActionTransport(ExtendAction):
2928
def __init__(
3029
self,

adf_core_python/implement/tactics/default_tactics_ambulance_team.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ def think(
141141
entity_id = agent_info.get_entity_id() # noqa: F841
142142

143143
self._logger.debug(
144-
f"received messages: {[str(message) for message in message_manager.get_received_message_list()]}, help: {message_manager.get_heard_agent_help_message_count()}",
145-
message_manager=message_manager,
144+
f"received messages: {[str(message) for message in message_manager.get_received_message_list()]}, help: {message_manager.get_heard_agent_help_message_count()}"
146145
)
147146

148147
for message in message_manager.get_received_message_list():

0 commit comments

Comments
 (0)