<div dir="ltr">There's an obligatory XKCD reference for this: <a href="http://xkcd.com/1172/">http://xkcd.com/1172/</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 6, 2015 at 12:25 PM, Terry Reedy <span dir="ltr"><<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 1/6/2015 7:39 AM, Victor Stinner wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
More context:<br>
<br>
2014-12-19 12:43 GMT+01:00 anatoly techtonik <<a href="mailto:techtonik@gmail.com" target="_blank">techtonik@gmail.com</a>>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<a href="https://github.com/nickstenning/honcho/pull/121" target="_blank">https://github.com/<u></u>nickstenning/honcho/pull/121</a><br>
</blockquote>
<br>
The link mentions the following changeset:<br>
---<br>
changeset:   93122:1a3143752db2<br>
branch:      2.7<br>
parent:      93112:927cca0b9337<br>
user:        R David Murray <<a href="mailto:rdmurray@bitdance.com" target="_blank">rdmurray@bitdance.com</a>><br>
date:        Fri Oct 17 20:07:08 2014 -0400<br>
files:       Lib/argparse.py Lib/test/test_argparse.py Misc/NEWS<br>
description:<br>
#9351: set_defaults on subparser is no longer ignored if set on parent.<br>
<br>
Before, if a default was set on the parent parser, any default for that<br>
variable set via set_defaults on a subparser would be ignored.  Now<br>
the subparser set_defaults is honored.<br>
<br>
Patch by Jyrki Pullianinen.<br>
<br>
<br>
diff -r 927cca0b9337 -r 1a3143752db2 Lib/argparse.py<br>
--- a/Lib/argparse.py   Fri Oct 17 16:20:15 2014 -0500<br>
+++ b/Lib/argparse.py   Fri Oct 17 20:07:08 2014 -0400<br>
@@ -1089,7 +1089,14 @@ class _SubParsersAction(Action):<br>
          # parse all the remaining options into the namespace<br>
          # store any unrecognized options on the object, so that the top<br>
          # level parser can decide what to do with them<br>
-        namespace, arg_strings = parser.parse_known_args(arg_<u></u>strings,<br>
namespace)<br>
+<br>
+        # In case this subparser defines new defaults, we parse them<br>
+        # in a new namespace object and then update the original<br>
+        # namespace for the relevant parts.<br>
+        subnamespace, arg_strings = parser.parse_known_args(arg_<u></u>strings, None)<br>
+        for key, value in vars(subnamespace).items():<br>
+            setattr(namespace, key, value)<br>
+<br>
          if arg_strings:<br>
              vars(namespace).setdefault(_<u></u>UNRECOGNIZED_ARGS_ATTR, [])<br>
              getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).<u></u>extend(arg_strings)<br>
---<br>
<br>
Which is related to <a href="http://bugs.python.org/issue9351" target="_blank">http://bugs.python.org/<u></u>issue9351</a><br>
<br>
Maybe argparse just became more strict? I don't understand the issue.<br>
</blockquote>
<br></div></div>
Steven Bethard, the argparse maintainer, defined the old behavior of ignoring subparser defaults (where there are also top level defaults) as a bug "counter to what people probably expect".  If the old behavior had been documented, changing it in a bug-fix release would have been a mistake.  But looking at the patch, the doc seems to have been silent on the issue.<br>
<br>
This is not the first time someone considered a 'bug fix' to be a 'regression', which it might be from their viewpoint.  The last comment on the github thread suggests that an easy fix was found.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Terry Jan Reedy</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/<u></u>mailman/options/python-dev/<u></u>guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div>
</div>