@@ -526,12 +526,13 @@ def _format_action(self, action):
526526 parts = [action_header ]
527527
528528 # if there was help for the action, add lines of help text
529- if action .help :
529+ if action .help and action . help . strip () :
530530 help_text = self ._expand_help (action )
531- help_lines = self ._split_lines (help_text , help_width )
532- parts .append ('%*s%s\n ' % (indent_first , '' , help_lines [0 ]))
533- for line in help_lines [1 :]:
534- parts .append ('%*s%s\n ' % (help_position , '' , line ))
531+ if help_text :
532+ help_lines = self ._split_lines (help_text , help_width )
533+ parts .append ('%*s%s\n ' % (indent_first , '' , help_lines [0 ]))
534+ for line in help_lines [1 :]:
535+ parts .append ('%*s%s\n ' % (help_position , '' , line ))
535536
536537 # or add a newline if the description doesn't end with one
537538 elif not action_header .endswith ('\n ' ):
@@ -1208,7 +1209,8 @@ def __call__(self, parser, namespace, values, option_string=None):
12081209 # namespace for the relevant parts.
12091210 subnamespace , arg_strings = parser .parse_known_args (arg_strings , None )
12101211 for key , value in vars (subnamespace ).items ():
1211- setattr (namespace , key , value )
1212+ if not hasattr (namespace , key ):
1213+ setattr (namespace , key , value )
12121214
12131215 if arg_strings :
12141216 vars (namespace ).setdefault (_UNRECOGNIZED_ARGS_ATTR , [])
@@ -1842,11 +1844,6 @@ def parse_known_args(self, args=None, namespace=None):
18421844 if action .default is not SUPPRESS :
18431845 setattr (namespace , action .dest , action .default )
18441846
1845- # add any parser defaults that aren't present
1846- for dest in self ._defaults :
1847- if not hasattr (namespace , dest ):
1848- setattr (namespace , dest , self ._defaults [dest ])
1849-
18501847 # parse the arguments and exit if there are any errors
18511848 if self .exit_on_error :
18521849 try :
@@ -1857,6 +1854,11 @@ def parse_known_args(self, args=None, namespace=None):
18571854 else :
18581855 namespace , args = self ._parse_known_args (args , namespace )
18591856
1857+ # add any parser defaults that aren't present
1858+ for dest in self ._defaults :
1859+ if not hasattr (namespace , dest ):
1860+ setattr (namespace , dest , self ._defaults [dest ])
1861+
18601862 if hasattr (namespace , _UNRECOGNIZED_ARGS_ATTR ):
18611863 args .extend (getattr (namespace , _UNRECOGNIZED_ARGS_ATTR ))
18621864 delattr (namespace , _UNRECOGNIZED_ARGS_ATTR )
0 commit comments