]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42501: Revise the usage note for Enums with the choices (GH-23563)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Mon, 30 Nov 2020 17:55:13 +0000 (09:55 -0800)
committerGitHub <noreply@github.com>
Mon, 30 Nov 2020 17:55:13 +0000 (09:55 -0800)
Doc/library/argparse.rst

index 7a7a4cf94979a19ee5170183bb101a37725a7515..a32b99901a7b4e2b6b532664b16f03faca0ab352 100644 (file)
@@ -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