diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index ef2fd42783c8772..a3e0ac7ce2231b9 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -672,7 +672,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_ - An iterable of the allowable values for the argument. * required_ - Whether or not the command-line option may be omitted (optionals only). @@ -1076,7 +1076,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 an iterable 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:: @@ -1090,9 +1090,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* iterable is checked after any type_ conversions have been performed, so the type of the objects in the *choices* -container should match the type_ specified:: +iterable should match the type_ specified:: >>> parser = argparse.ArgumentParser(prog='doors.py') >>> parser.add_argument('door', type=int, choices=range(1, 4)) @@ -1103,7 +1103,7 @@ container should match the type_ specified:: doors.py: error: argument door: invalid choice: 4 (choose from 1, 2, 3) Any object that supports the ``in`` operator can be passed as the *choices* -value, so :class:`dict` objects, :class:`set` objects, custom containers, +value, so :class:`dict` objects, :class:`set` objects, custom iterables, etc. are all supported. diff --git a/Lib/argparse.py b/Lib/argparse.py index a300828f9e3d2ea..8e65ee31325455f 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -784,7 +784,7 @@ class Action(_AttributeHolder): float, and complex are useful examples of such callables. If None, str is used. - - choices -- A container of values that should be allowed. If not None, + - choices -- An iterable of values that should be allowed. If not None, after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection. diff --git a/Misc/NEWS.d/next/Documentation/2019-08-08-10-31-23.bpo-37793.o0Akc8.rst b/Misc/NEWS.d/next/Documentation/2019-08-08-10-31-23.bpo-37793.o0Akc8.rst new file mode 100644 index 000000000000000..0b9141863cb6f29 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2019-08-08-10-31-23.bpo-37793.o0Akc8.rst @@ -0,0 +1,3 @@ +Changed the wording in the argparse documentation and argparse.py docstring +by removing the usage of the word "container" and replace it with +"iterable".