From 7c1bae1733381e58a313ff09de9163ccdc7dff78 Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Fri, 10 Jul 2026 16:49:20 -0400 Subject: [PATCH 1/2] Fix typing on optional strings Rebase PR #5727 on develop branch --- com.unity.ml-agents/CHANGELOG.md | 1 + ml-agents-envs/mlagents_envs/timers.py | 5 ++++- ml-agents/mlagents/trainers/directory_utils.py | 3 ++- ml-agents/mlagents/trainers/trainer/trainer_factory.py | 4 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 26102b8958e..bb93bcfeb0e 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to #### ml-agents / ml-agents-envs - Fixed a bug when using LSTM and SAC where the buffer might contain non-integer numbers of sequences. (#6301) - Fixed mixed CPU/GPU computation by ensuring tensors share a consistent device in the trainer; Updated training devices. (#6303) +- Fix typing on optional strings #### Examples - Replace hardcoded value 200f by agentRotationSpeed in MoveAgent() (#6306) diff --git a/ml-agents-envs/mlagents_envs/timers.py b/ml-agents-envs/mlagents_envs/timers.py index 32b8602c9cc..f2307303388 100644 --- a/ml-agents-envs/mlagents_envs/timers.py +++ b/ml-agents-envs/mlagents_envs/timers.py @@ -71,7 +71,10 @@ def add_time(self, elapsed: float) -> None: self.count += 1 def merge( - self, other: "TimerNode", root_name: str = None, is_parallel: bool = True + self, + other: "TimerNode", + root_name: Optional[str] = None, + is_parallel: bool = True, ) -> None: """ Add the other node to this node, then do the same recursively on its children. diff --git a/ml-agents/mlagents/trainers/directory_utils.py b/ml-agents/mlagents/trainers/directory_utils.py index 80379d81e99..5e979fab93b 100644 --- a/ml-agents/mlagents/trainers/directory_utils.py +++ b/ml-agents/mlagents/trainers/directory_utils.py @@ -1,11 +1,12 @@ import os +from typing import Optional from mlagents.trainers.exception import UnityTrainerException from mlagents.trainers.settings import TrainerSettings from mlagents.trainers.model_saver.torch_model_saver import DEFAULT_CHECKPOINT_NAME def validate_existing_directories( - output_path: str, resume: bool, force: bool, init_path: str = None + output_path: str, resume: bool, force: bool, init_path: Optional[str] = None ) -> None: """ Validates that if the run_id model exists, we do not overwrite it unless --force is specified. diff --git a/ml-agents/mlagents/trainers/trainer/trainer_factory.py b/ml-agents/mlagents/trainers/trainer/trainer_factory.py index ffb77415133..c5b0cfd49d1 100644 --- a/ml-agents/mlagents/trainers/trainer/trainer_factory.py +++ b/ml-agents/mlagents/trainers/trainer/trainer_factory.py @@ -1,5 +1,5 @@ import os -from typing import Dict +from typing import Dict, Optional from mlagents_envs.logging_util import get_logger from mlagents.trainers.environment_parameter_manager import EnvironmentParameterManager @@ -23,7 +23,7 @@ def __init__( load_model: bool, seed: int, param_manager: EnvironmentParameterManager, - init_path: str = None, + init_path: Optional[str] = None, multi_gpu: bool = False, ): """ From b9bc15d8b6000dda0bdcf91270c6505a3df83086 Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Fri, 10 Jul 2026 16:52:56 -0400 Subject: [PATCH 2/2] update changelog --- com.unity.ml-agents/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index bb93bcfeb0e..0237b6c34ed 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -19,7 +19,7 @@ and this project adheres to #### ml-agents / ml-agents-envs - Fixed a bug when using LSTM and SAC where the buffer might contain non-integer numbers of sequences. (#6301) - Fixed mixed CPU/GPU computation by ensuring tensors share a consistent device in the trainer; Updated training devices. (#6303) -- Fix typing on optional strings +- Fix typing on optional strings (#6311) #### Examples - Replace hardcoded value 200f by agentRotationSpeed in MoveAgent() (#6306)