8000 bpo-42501: Revise the usage note for Enums with the choices (GH-2356… · python/cpython@aab9390 · GitHub
[go: up one dir, main page]

Skip to content

Commit aab9390

Browse files
bpo-42501: Revise the usage note for Enums with the choices (GH-23563) (GH-23573)
1 parent cf22aa3 commit aab9390

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

Doc/library/argparse.rst

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,20 +1133,9 @@ container should match the type_ specified::
11331133

11341134
Any container can be passed as the *choices* value, so :class:`list` objects,
11351135
:class:`set` objects, and custom containers are all supported.
1136-
This includes :class:`enum.Enum`, which could be used to restrain
1137-
argument's choices; if we reuse previous rock/paper/scissors game example,
1138-
this could be as follows::
1139-
1140-
>>> from enum import Enum
1141-
>>> class GameMove(Enum):
1142-
... ROCK = 'rock'
1143-
... PAPER = 'paper'
1144-
... SCISSORS = 'scissors'
1145-
...
1146-
>>> parser = argparse.ArgumentParser(prog='game.py')
1147-
>>> parser.add_argument('move', type=GameMove, choices=GameMove)
1148-
>>> parser.parse_args(['rock'])
1149-
Namespace(move=<GameMove.ROCK: 'rock'>)
1136+
1137+
Use of :class:`enum.Enum` is not recommended because it is difficult to
1138+
control its appearance in usage, help, and error messages.
11501139

11511140

11521141
required

0 commit comments

Comments
 (0)
0