paul j3 <[email protected]> added the comment:
I added a `print(args)` to clarify what you are talking about:
2148:~/mypy$ python3 issue36664.py subsection
Namespace(context='subsection')
my subsection was called
2148:~/mypy$ python3 issue36664.py s
Namespace(context='s')
my functon was not called <sadface>
2148:~/mypy$ python3 issue36664.py sub
Namespace(context='sub')
my functon was not called <sadface>
The value of `args.context` depends on what alias was used, not the primary
name of the subparser.
The help lists all aliases
2148:~/mypy$ python3 issue36664.py -h
usage: issue36664.py [-h] {subsection,s,sub,subsect} ...
The sub-parser doesn't actually have a name. In self._name_parser_map each
alias is a key with a parser object value. Multiple keys for a single value.
The only thing that distinguishes 'subsection' is that was the first key in
that dictionary.
In effect the subparser Action object does not maintain a mapping from the
aliases to the 'subsection' name. I can imagine some ways of deducing that
mapping, but it's not going to be a trivial task.
Unless someone comes up with a clever patch, I think the best choice is for you
maintain your own mapping. For example write a utility that takes a 'name' and
alias list, calls
sub = subparser.add_parser('subsection', aliases=['s', 'sub', 'subsect'])
and saves some sort of mapping from the aliases to 'subsection'. Then use that
later when you use `args.context`.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36664>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com