summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2022-12-26 01:10:48 -0600
committerGitHub <noreply@github.com>2022-12-26 01:10:48 -0600
commita167365d8585c373ff3bdff0d48bffb7e74581e5 (patch)
treee274e098891fbf8dd16f08a8c4d1ed10d0030bfe
parent9975d4e7bac052c320880e026f757cddaa91b4bf (diff)
downloadcpython-git-a167365d8585c373ff3bdff0d48bffb7e74581e5.tar.gz
[3.10] gh-92446: Improve argparse choices docs (GH-94627) (#100529)
Based on the definition of the collections.abc classes, it is more accurate to use "sequence" instead of "container" when describing argparse choices. (cherry picked from commit ad3c99e521) Co-authored-by: Guy Yagev <yourlefthandman8@gmail.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
-rw-r--r--Doc/library/argparse.rst12
1 files changed, 6 insertions, 6 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index bdc2ccebb7..3971c000b2 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -702,7 +702,7 @@ The add_argument() method
* type_ - The type to which the command-line argument should be converted.
- * choices_ - A container of the allowable values for the argument.
+ * choices_ - A sequence of the allowable values for the argument.
* required_ - Whether or not the command-line option may be omitted
(optionals only).
@@ -1124,7 +1124,7 @@ choices
^^^^^^^
Some command-line arguments should be selected from a restricted set of values.
-These can be handled by passing a container object as the *choices* keyword
+These can be handled by passing a sequence object as the *choices* keyword
argument to :meth:`~ArgumentParser.add_argument`. When the command line is
parsed, argument values will be checked, and an error message will be displayed
if the argument was not one of the acceptable values::
@@ -1138,9 +1138,9 @@ if the argument was not one of the acceptable values::
game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
'paper', 'scissors')
-Note that inclusion in the *choices* container is checked after any type_
+Note that inclusion in the *choices* sequence is checked after any type_
conversions have been performed, so the type of the objects in the *choices*
-container should match the type_ specified::
+sequence should match the type_ specified::
>>> parser = argparse.ArgumentParser(prog='doors.py')
>>> parser.add_argument('door', type=int, choices=range(1, 4))
@@ -1150,8 +1150,8 @@ container should match the type_ specified::
usage: doors.py [-h] {1,2,3}
doors.py: error: argument door: invalid choice: 4 (choose from 1, 2, 3)
-Any container can be passed as the *choices* value, so :class:`list` objects,
-:class:`set` objects, and custom containers are all supported.
+Any sequence can be passed as the *choices* value, so :class:`list` objects,
+:class:`tuple` objects, and custom sequences are all supported.
Use of :class:`enum.Enum` is not recommended because it is difficult to
control its appearance in usage, help, and error messages.