diff --git a/Lib/argparse.py b/Lib/argparse.py index 9c710cef5b6aaa..08918d89afca1b 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -727,6 +727,8 @@ def _get_action_name(argument): return argument.metavar elif argument.dest not in (None, SUPPRESS): return argument.dest + elif argument.choices not in (None, SUPPRESS): + return "{" + ','.join(argument.choices.keys()) + "}" else: return None diff --git a/Misc/NEWS.d/next/Library/2020-02-20-01-53-01.bpo-29298.laIn2S.rst b/Misc/NEWS.d/next/Library/2020-02-20-01-53-01.bpo-29298.laIn2S.rst new file mode 100644 index 00000000000000..270b545404140b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-02-20-01-53-01.bpo-29298.laIn2S.rst @@ -0,0 +1,2 @@ +Fix crash in :mod:`argparse` when using subparsers and its required attribute +is set to True.