[Python-checkins] bpo-42501: Revise the usage note for Enums with the choices (GH-23563) (GH-23573)

rhettinger webhook-mailer at python.org
Mon Nov 30 16:21:23 EST 2020


https://github.com/python/cpython/commit/aab93903347ec6d7f23dda2994dd26f6111d19d2
commit: aab93903347ec6d7f23dda2994dd26f6111d19d2
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2020年11月30日T13:21:08-08:00
summary:
bpo-42501: Revise the usage note for Enums with the choices (GH-23563) (GH-23573)
files:
M Doc/library/argparse.rst
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 7a7a4cf94979a..a32b99901a7b4 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -1133,20 +1133,9 @@ container should match the type_ specified::
 
 Any container can be passed as the *choices* value, so :class:`list` objects,
 :class:`set` objects, and custom containers are all supported.
-This includes :class:`enum.Enum`, which could be used to restrain
-argument's choices; if we reuse previous rock/paper/scissors game example,
-this could be as follows::
-
- >>> from enum import Enum
- >>> class GameMove(Enum):
- ... ROCK = 'rock'
- ... PAPER = 'paper'
- ... SCISSORS = 'scissors'
- ...
- >>> parser = argparse.ArgumentParser(prog='game.py')
- >>> parser.add_argument('move', type=GameMove, choices=GameMove)
- >>> parser.parse_args(['rock'])
- Namespace(move=<GameMove.ROCK: 'rock'>)
+
+Use of :class:`enum.Enum` is not recommended because it is difficult to
+control its appearance in usage, help, and error messages.
 
 
 required


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /