- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
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 | ALSchwalm, miss-islington, paul.j3, rhettinger |
| Date | 2021-10-27.21:41:36 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1635370896.22.0.376820847545.issue45235@roundup.psfhosted.org> |
| In-reply-to |
| Content |
|---|
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. |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2021-10-27 21:41:36 | paul.j3 | set | recipients: + paul.j3, rhettinger, miss-islington, ALSchwalm |
| 2021-10-27 21:41:36 | paul.j3 | set | messageid: <1635370896.22.0.376820847545.issue45235@roundup.psfhosted.org> |
| 2021-10-27 21:41:36 | paul.j3 | link | issue45235 messages |
| 2021-10-27 21:41:36 | paul.j3 | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
