@@ -105,13 +105,15 @@ def to_bool(value: TomlTypes) -> bool:
105105
106106 @staticmethod
107107 def to_list (value : TomlTypes , of_type : type [_T ]) -> Iterator [_T ]:
108- result = validate (value , cast ("type[list[Any]]" , GenericAlias (list , (of_type ,))))
109- return iter (cast ("list[_T]" , result ))
108+ result = cast ("list[_T]" , validate (value , cast ("type[list[Any]]" , GenericAlias (list , (of_type ,)))))
109+ if inspect .isclass (of_type ) and issubclass (of_type , Command ):
110+ # a generated command list leaves gaps rather than compacting itself, so drop them here (see #3388)
111+ return iter ([i for i in result if i ])
112+ return iter (result )
110113
111114 @staticmethod
112115 def to_set (value : TomlTypes , of_type : type [_T ]) -> Iterator [_T ]:
113- result = validate (value , cast ("type[list[Any]]" , GenericAlias (list , (of_type ,))))
114- return iter (cast ("list[_T]" , result ))
116+ return TomlLoader .to_list (value , of_type )
115117
116118 @staticmethod
117119 def to_dict (value : TomlTypes , of_type : tuple [type [_T ], type [_V ]]) -> Iterator [tuple [_T , _V ]]:
@@ -123,10 +125,11 @@ def to_path(value: TomlTypes) -> Path:
123125 return Path (TomlLoader .to_str (value ))
124126
125127 @staticmethod
126- def to_command (value : TomlTypes ) -> Command | None :
127- if value :
128- return Command (args = cast ("list[str]" , value )) # validated during load in _ensure_type_correct
129- return None
128+ def to_command (value : TomlTypes ) -> Command :
129+ if not value :
130+ msg = f"attempting to parse { value !r} into a command failed"
131+ raise ValueError (msg )
132+ return Command (args = cast ("list[str]" , value )) # validated during load in _ensure_type_correct
130133
131134 @staticmethod
132135 def to_env_list (value : TomlTypes ) -> EnvList :
0 commit comments