@@ -49,12 +49,13 @@ def unparse_arg(self, arg: t.Any) -> str: # pylint: disable = no-self-use
4949 def unparse_args (self , arguments : t .Sequence [t .Any ],
5050 * , to_list : bool = False ) -> t .Union [str , t .List [str ]]:
5151 """Convert list to string of command-line args."""
52- unparsed = []
52+ unparsed_list = []
5353 for arg in arguments :
54- unparsed .append (self .unparse_arg (arg ))
55- _LOG .debug ('%s: unparsed args to %s' , self , unparsed )
56- if not to_list :
57- unparsed = ' ' .join (unparsed )
54+ unparsed_list .append (self .unparse_arg (arg ))
55+ _LOG .debug ('%s: unparsed args to %s' , self , unparsed_list )
56+ if to_list :
57+ return unparsed_list
58+ unparsed = ' ' .join (unparsed_list )
5859 _LOG .debug ('%s: converted unparsed args to string "%s"' , self , unparsed )
5960 return unparsed
6061
@@ -63,15 +64,15 @@ def unparse_option(self, key: str, value: t.Any,
6364 """Convert a key-value pair into a string that can be used as a command-line option."""
6465 if option_should_be_skipped (value ):
6566 return [] if to_list else ''
66- unparsed_key = '{}{}' . format ( self ._long_opt if len (key ) > 1 else self ._short_opt , key )
67+ unparsed_key = f' { self ._long_opt if len (key ) > 1 else self ._short_opt } { key } '
6768 if not treat_as_option_with_no_value (value ):
6869 unparsed_value = self .unparse_arg (value )
6970 if to_list and (self ._opt_value == ' ' or treat_as_option_with_no_value (value )):
7071 if treat_as_option_with_no_value (value ):
7172 return [unparsed_key ]
7273 return [unparsed_key , unparsed_value ]
7374 if not treat_as_option_with_no_value (value ):
74- unparsed_option = '{}{}{}' . format ( unparsed_key , self ._opt_value , unparsed_value )
75+ unparsed_option = f' { unparsed_key } { self ._opt_value } { unparsed_value } '
7576 if to_list :
7677 return [unparsed_option ]
7778 if treat_as_option_with_no_value (value ):
@@ -81,18 +82,20 @@ def unparse_option(self, key: str, value: t.Any,
8182 def unparse_options (self , options : t .Mapping [str , t .Any ],
8283 * , to_list : bool = False ) -> t .Union [str , t .List [str ]]:
8384 """Convert dictionary to string of command-line args."""
84- unparsed = []
85+ unparsed_list : t . List [ str ] = []
8586 for key , value in options .items ():
8687 if option_should_be_skipped (value ):
8788 continue
8889 unparsed_option = self .unparse_option (key , value , to_list = to_list )
8990 if to_list :
90- unparsed += unparsed_option
91+ unparsed_list += unparsed_option
9192 else :
92- unparsed .append (unparsed_option )
93- _LOG .debug ('%s: unparsed options to %s' , self , unparsed )
94- if not to_list :
95- unparsed = ' ' .join (unparsed )
93+ assert isinstance (unparsed_option , str ), type (unparsed_option )
94+ unparsed_list .append (unparsed_option )
95+ _LOG .debug ('%s: unparsed options to %s' , self , unparsed_list )
96+ if to_list :
97+ return unparsed_list
98+ unparsed = ' ' .join (unparsed_list )
9699 _LOG .debug ('%s: converted unparsed options to string "%s"' , self , unparsed )
97100 return unparsed
98101
0 commit comments