[New-bugs-announce] [issue34188] Use dicts to "transform" argparse arguments to values

Victor Porton report at bugs.python.org
Sun Jul 22 08:53:50 EDT 2018


New submission from Victor Porton <porton at narod.ru>:

The below code produces "rock", but it should produce "a". This (to use dict value instead of the key by argparse result) is both to be a new useful feature (for example to map strings in a command line to certain functions or classes provided as dict values) and conform to intuition better.

My feature proposal breaks backward compatibility, but I think no reasonable programmer wrote it in such a way that he relied on the current behavior for `dict` values for `choices`.

import argparse

parser = argparse.ArgumentParser(prog='game.py')
parser.add_argument('move', choices={'rock':'a', 'paper':'b', 'scissors':'c'})
print(parser.parse_args(['rock']))

----------
components: Library (Lib)
messages: 322142
nosy: porton
priority: normal
severity: normal
status: open
title: Use dicts to "transform" argparse arguments to values
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34188>
_______________________________________


More information about the New-bugs-announce mailing list