diff --git a/smartsim/settings/base.py b/smartsim/settings/base.py index 680800f8a..262476bc9 100644 --- a/smartsim/settings/base.py +++ b/smartsim/settings/base.py @@ -455,13 +455,17 @@ def add_exe_args(self, args: t.Union[str, t.List[str]]) -> None: :type args: str | list[str] :raises TypeError: if exe args are not strings """ + + if not isinstance(args, (list, str)): + raise TypeError("All elements in the list should be of type str") + if isinstance(args, str): args = args.split() - for arg in args: - if not isinstance(arg, str): - raise TypeError("Executable arguments should be a list of str") - + if isinstance(args, list): + if not all(isinstance(arg, str) for arg in args): + raise TypeError("All elements in the list should be of type str") + self._exe_args.extend(args) def set( @@ -545,13 +549,6 @@ def _build_exe_args(exe_args: t.Optional[t.Union[str, t.List[str]]]) -> t.List[s if isinstance(exe_args, str): return exe_args.split() if isinstance(exe_args, list): - exe_args = copy.deepcopy(exe_args) - nested_type = all( - all(isinstance(arg, (str)) for arg in exe_args_list) - for exe_args_list in exe_args - ) - if not nested_type: - raise TypeError("Executable arguments were not list of str or str") return exe_args return [] diff --git a/tests/test_run_settings.py b/tests/test_run_settings.py index 6eb51cb71..eafd43261 100644 --- a/tests/test_run_settings.py +++ b/tests/test_run_settings.py @@ -207,10 +207,10 @@ def test_add_exe_args_list_of_mixed_lists_init(): """Ensure that any non-string exe arg fails validation for all""" exe_args = [["1", "2", 3], ["4", "5", 6]] - with pytest.raises(TypeError) as type_error: - settings = RunSettings("python", exe_args=exe_args) + with pytest.raises(TypeError) as type_error: + _ = RunSettings("python", exe_args=exe_args) - assert "Executable arguments should be a list of str" in type_error.value.args + assert "Executable arguments were not list of str or str." in type_error.value.args def test_add_exe_args_list_of_str_lists_init():