This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients bethard, ezio.melotti, mikn, nailor, paul.j3, petri.lehtinen, python-dev, r.david.murray
Date 2014-10-27.02:25:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1414376738.89.0.482780407444.issue9351@psf.upfronthosting.co.za>
In-reply-to
Content
I'm exploring modifying that patch by adding a 'subnamespace' attribute to the subparsers Action object.  This would give the user, or the main parser control over the namespace that is passed to a subparser.

For example: 

        subnamespace = getattr(self, 'subnamespace', False)
        if subnamespace is None:
            pass
        elif not  subnamespace:
            subnamespace = namespace
        # if None, subparser will use a fresh one
        subnamespace, arg_strings = parser.parse_known_args(arg_strings, subnamespace)
        for key, value in vars(subnamespace).items():
            setattr(namespace, key, value)

As written here, no value (or any False) would use the main parser namespace, as done with existing code.

A 'None' value, would use the a new empty namespace, as proposed in this patch.

Or the user could directly define the namespace, e.g.

    sp = parser.add_subparsers()
    sp.subnamespace = Namespace(foo=4)

That could also be convenient if the user is using a custom Namespace class.

'parse_known_args' could also set this attribute, based on whether the user has given it a namespace or not.
History
Date User Action Args
2014-10-27 02:25:39paul.j3setrecipients: + paul.j3, bethard, ezio.melotti, r.david.murray, nailor, python-dev, petri.lehtinen, mikn
2014-10-27 02:25:38paul.j3setmessageid: <1414376738.89.0.482780407444.issue9351@psf.upfronthosting.co.za>
2014-10-27 02:25:38paul.j3linkissue9351 messages
2014-10-27 02:25:37paul.j3create