gh-92446: Improve argparse choices docs; revert bad change to lzma docs (#94627)

Based on the definition of the collections.abc classes, it is more accurate to use "sequence" instead of "container" when describing argparse choices.

A previous attempt at fixing this in #92450 was mistaken; this PR reverts that change.

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
Guy Yagev 2022-12-26 08:22:53 +02:00 committed by GitHub
parent dbc1e696eb
commit ad3c99e521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -765,7 +765,7 @@ The add_argument() method
* type_ - The type to which the command-line argument should be converted. * 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 * required_ - Whether or not the command-line option may be omitted
(optionals only). (optionals only).
@ -1209,7 +1209,7 @@ choices
^^^^^^^ ^^^^^^^
Some command-line arguments should be selected from a restricted set of values. 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 argument to :meth:`~ArgumentParser.add_argument`. When the command line is
parsed, argument values will be checked, and an error message will be displayed parsed, argument values will be checked, and an error message will be displayed
if the argument was not one of the acceptable values:: if the argument was not one of the acceptable values::
@ -1223,9 +1223,9 @@ if the argument was not one of the acceptable values::
game.py: error: argument move: invalid choice: 'fire' (choose from 'rock', game.py: error: argument move: invalid choice: 'fire' (choose from 'rock',
'paper', 'scissors') '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* 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 = argparse.ArgumentParser(prog='doors.py')
>>> parser.add_argument('door', type=int, choices=range(1, 4)) >>> parser.add_argument('door', type=int, choices=range(1, 4))
@ -1235,8 +1235,8 @@ container should match the type_ specified::
usage: doors.py [-h] {1,2,3} usage: doors.py [-h] {1,2,3}
doors.py: error: argument door: invalid choice: 4 (choose from 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, Any sequence can be passed as the *choices* value, so :class:`list` objects,
:class:`set` objects, and custom containers are all supported. :class:`tuple` objects, and custom sequences are all supported.
Use of :class:`enum.Enum` is not recommended because it is difficult to Use of :class:`enum.Enum` is not recommended because it is difficult to
control its appearance in usage, help, and error messages. control its appearance in usage, help, and error messages.

View file

@ -147,7 +147,7 @@ Compressing and decompressing data in memory
This format is more limited than ``.xz`` -- it does not support integrity This format is more limited than ``.xz`` -- it does not support integrity
checks or multiple filters. checks or multiple filters.
* :const:`FORMAT_RAW`: A raw data stream, not using sequences format. * :const:`FORMAT_RAW`: A raw data stream, not using any container format.
This format specifier does not support integrity checks, and requires that This format specifier does not support integrity checks, and requires that
you always specify a custom filter chain (for both compression and you always specify a custom filter chain (for both compression and
decompression). Additionally, data compressed in this manner cannot be decompression). Additionally, data compressed in this manner cannot be