Message230056
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. |
|
Date |
User |
Action |
Args |
2014-10-27 02:25:39 | paul.j3 | set | recipients:
+ paul.j3, bethard, ezio.melotti, r.david.murray, nailor, python-dev, petri.lehtinen, mikn |
2014-10-27 02:25:38 | paul.j3 | set | messageid: <1414376738.89.0.482780407444.issue9351@psf.upfronthosting.co.za> |
2014-10-27 02:25:38 | paul.j3 | link | issue9351 messages |
2014-10-27 02:25:37 | paul.j3 | create | |
|