paul j3 <ajipa...@gmail.com> added the comment:

I should study previous posts in more detail, but here are some thoughts on 
correctly handling user namespace.

At the start of `parse_known_args`, there's a

        if namespace is None:
            namespace = Namespace()

We need to hang on to a copy of this namespace, e.g. call it

        import copy
        orig_namespace = copy.copy(namespace)

In _SubParsersAction.__call__, pass this copy to the subparser (instead of 
None):

    subnamespace, arg_strings = parser.parse_known_args(arg_strings, 
orig_namespace)
        for key, value in vars(subnamespace).items():
            setattr(namespace, key, value)

Prior to 9351, the main namespace was passed to the subparser

    namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)

The trick is to get orig_namespace from the main parse_known_args to 
SubParsersAction.__call__ method.

in a 9351 post I explore the idea of allowing the user to specify a 
'sub_namespace' for the subparser.

https://bugs.python.org/msg230056

In any case, this is a complicated issue that needs careful thought and more 
extensive testing.  I didn't entirely like the original 9351 change, but since 
that's been part of argparse for many years, we need to very careful about 
clobbering it.

----------
status: pending -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45235>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to