Skip to content

Commit 8d9d009

Browse files
Merge branch 'main' into str-format-errors
2 parents c5b1321 + d4fa707 commit 8d9d009

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1307
-143
lines changed

Doc/howto/functional.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Functional Programming HOWTO
55
********************************
66

7-
:Author: A. M. Kuchling
7+
:Author: \A. M. Kuchling
88
:Release: 0.32
99

1010
In this document, we'll take a tour of Python's features suitable for

Doc/howto/urllib2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Introduction
1515
You may also find useful the following article on fetching web resources
1616
with Python:
1717

18-
* `Basic Authentication <https://web.archive.org/web/20201215133350/http://www.voidspace.org.uk/python/articles/authentication.shtml>`_
18+
* `Basic Authentication <https://web.archive.org/web/20201215133350/http://www.voidspace.org.uk/python/articles/authentication.shtml>`__
1919

2020
A tutorial on *Basic Authentication*, with examples in Python.
2121

Doc/library/argparse.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,9 @@ how the command-line arguments should be handled. The supplied actions are:
767767
Namespace(foo=42)
768768

769769
* ``'store_true'`` and ``'store_false'`` - These are special cases of
770-
``'store_const'`` used for storing the values ``True`` and ``False``
771-
respectively. In addition, they create default values of ``False`` and
772-
``True`` respectively::
770+
``'store_const'`` that respectively store the values ``True`` and ``False``
771+
with default values of ``False`` and
772+
``True``::
773773

774774
>>> parser = argparse.ArgumentParser()
775775
>>> parser.add_argument('--foo', action='store_true')
@@ -789,8 +789,8 @@ how the command-line arguments should be handled. The supplied actions are:
789789
>>> parser.parse_args('--foo 1 --foo 2'.split())
790790
Namespace(foo=['0', '1', '2'])
791791

792-
* ``'append_const'`` - This stores a list, and appends the value specified by
793-
the const_ keyword argument to the list; note that the const_ keyword
792+
* ``'append_const'`` - This appends the value specified by
793+
the const_ keyword argument to a list; note that the const_ keyword
794794
argument defaults to ``None``. The ``'append_const'`` action is typically
795795
useful when multiple arguments need to store constants to the same list. For
796796
example::
@@ -801,8 +801,8 @@ how the command-line arguments should be handled. The supplied actions are:
801801
>>> parser.parse_args('--str --int'.split())
802802
Namespace(types=[<class 'str'>, <class 'int'>])
803803

804-
* ``'extend'`` - This stores a list and appends each item from the multi-value
805-
argument list to it.
804+
* ``'extend'`` - This appends each item from a multi-value
805+
argument to a list.
806806
The ``'extend'`` action is typically used with the nargs_ keyword argument
807807
value ``'+'`` or ``'*'``.
808808
Note that when nargs_ is ``None`` (the default) or ``'?'``, each
@@ -816,7 +816,7 @@ how the command-line arguments should be handled. The supplied actions are:
816816

817817
.. versionadded:: 3.8
818818

819-
* ``'count'`` - This counts the number of times a keyword argument occurs. For
819+
* ``'count'`` - This counts the number of times an argument occurs. For
820820
example, this is useful for increasing verbosity levels::
821821

822822
>>> parser = argparse.ArgumentParser()

Doc/library/decimal.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,20 +2109,20 @@ to work with the :class:`Decimal` class::
21092109
Decimal FAQ
21102110
-----------
21112111

2112-
Q. It is cumbersome to type ``decimal.Decimal('1234.5')``. Is there a way to
2112+
Q: It is cumbersome to type ``decimal.Decimal('1234.5')``. Is there a way to
21132113
minimize typing when using the interactive interpreter?
21142114

2115-
A. Some users abbreviate the constructor to just a single letter:
2115+
A: Some users abbreviate the constructor to just a single letter:
21162116

21172117
>>> D = decimal.Decimal
21182118
>>> D('1.23') + D('3.45')
21192119
Decimal('4.68')
21202120

2121-
Q. In a fixed-point application with two decimal places, some inputs have many
2121+
Q: In a fixed-point application with two decimal places, some inputs have many
21222122
places and need to be rounded. Others are not supposed to have excess digits
21232123
and need to be validated. What methods should be used?
21242124

2125-
A. The :meth:`~Decimal.quantize` method rounds to a fixed number of decimal places. If
2125+
A: The :meth:`~Decimal.quantize` method rounds to a fixed number of decimal places. If
21262126
the :const:`Inexact` trap is set, it is also useful for validation:
21272127

21282128
>>> TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
@@ -2140,10 +2140,10 @@ the :const:`Inexact` trap is set, it is also useful for validation:
21402140
...
21412141
Inexact: None
21422142

2143-
Q. Once I have valid two place inputs, how do I maintain that invariant
2143+
Q: Once I have valid two place inputs, how do I maintain that invariant
21442144
throughout an application?
21452145

2146-
A. Some operations like addition, subtraction, and multiplication by an integer
2146+
A: Some operations like addition, subtraction, and multiplication by an integer
21472147
will automatically preserve fixed point. Others operations, like division and
21482148
non-integer multiplication, will change the number of decimal places and need to
21492149
be followed-up with a :meth:`~Decimal.quantize` step:
@@ -2175,21 +2175,21 @@ to handle the :meth:`~Decimal.quantize` step:
21752175
>>> div(b, a)
21762176
Decimal('0.03')
21772177

2178-
Q. There are many ways to express the same value. The numbers ``200``,
2178+
Q: There are many ways to express the same value. The numbers ``200``,
21792179
``200.000``, ``2E2``, and ``.02E+4`` all have the same value at
21802180
various precisions. Is there a way to transform them to a single recognizable
21812181
canonical value?
21822182

2183-
A. The :meth:`~Decimal.normalize` method maps all equivalent values to a single
2183+
A: The :meth:`~Decimal.normalize` method maps all equivalent values to a single
21842184
representative:
21852185

21862186
>>> values = map(Decimal, '200 200.000 2E2 .02E+4'.split())
21872187
>>> [v.normalize() for v in values]
21882188
[Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2')]
21892189

2190-
Q. When does rounding occur in a computation?
2190+
Q: When does rounding occur in a computation?
21912191

2192-
A. It occurs *after* the computation. The philosophy of the decimal
2192+
A: It occurs *after* the computation. The philosophy of the decimal
21932193
specification is that numbers are considered exact and are created
21942194
independent of the current context. They can even have greater
21952195
precision than current context. Computations process with those
@@ -2207,10 +2207,10 @@ applied to the *result* of the computation::
22072207
>>> pi + 0 - Decimal('0.00005'). # Intermediate values are rounded
22082208
Decimal('3.1416')
22092209

2210-
Q. Some decimal values always print with exponential notation. Is there a way
2210+
Q: Some decimal values always print with exponential notation. Is there a way
22112211
to get a non-exponential representation?
22122212

2213-
A. For some values, exponential notation is the only way to express the number
2213+
A: For some values, exponential notation is the only way to express the number
22142214
of significant places in the coefficient. For example, expressing
22152215
``5.0E+3`` as ``5000`` keeps the value constant but cannot show the
22162216
original's two-place significance.
@@ -2225,9 +2225,9 @@ value unchanged:
22252225
>>> remove_exponent(Decimal('5E+3'))
22262226
Decimal('5000')
22272227

2228-
Q. Is there a way to convert a regular float to a :class:`Decimal`?
2228+
Q: Is there a way to convert a regular float to a :class:`Decimal`?
22292229

2230-
A. Yes, any binary floating-point number can be exactly expressed as a
2230+
A: Yes, any binary floating-point number can be exactly expressed as a
22312231
Decimal though an exact conversion may take more precision than intuition would
22322232
suggest:
22332233

@@ -2236,19 +2236,19 @@ suggest:
22362236
>>> Decimal(math.pi)
22372237
Decimal('3.141592653589793115997963468544185161590576171875')
22382238

2239-
Q. Within a complex calculation, how can I make sure that I haven't gotten a
2239+
Q: Within a complex calculation, how can I make sure that I haven't gotten a
22402240
spurious result because of insufficient precision or rounding anomalies.
22412241

2242-
A. The decimal module makes it easy to test results. A best practice is to
2242+
A: The decimal module makes it easy to test results. A best practice is to
22432243
re-run calculations using greater precision and with various rounding modes.
22442244
Widely differing results indicate insufficient precision, rounding mode issues,
22452245
ill-conditioned inputs, or a numerically unstable algorithm.
22462246

2247-
Q. I noticed that context precision is applied to the results of operations but
2247+
Q: I noticed that context precision is applied to the results of operations but
22482248
not to the inputs. Is there anything to watch out for when mixing values of
22492249
different precisions?
22502250

2251-
A. Yes. The principle is that all values are considered to be exact and so is
2251+
A: Yes. The principle is that all values are considered to be exact and so is
22522252
the arithmetic on those values. Only the results are rounded. The advantage
22532253
for inputs is that "what you type is what you get". A disadvantage is that the
22542254
results can look odd if you forget that the inputs haven't been rounded:
@@ -2276,9 +2276,9 @@ Alternatively, inputs can be rounded upon creation using the
22762276
>>> Context(prec=5, rounding=ROUND_DOWN).create_decimal('1.2345678')
22772277
Decimal('1.2345')
22782278

2279-
Q. Is the CPython implementation fast for large numbers?
2279+
Q: Is the CPython implementation fast for large numbers?
22802280

2281-
A. Yes. In the CPython and PyPy3 implementations, the C/CFFI versions of
2281+
A: Yes. In the CPython and PyPy3 implementations, the C/CFFI versions of
22822282
the decimal module integrate the high speed `libmpdec
22832283
<https://www.bytereef.org/mpdecimal/doc/libmpdec/index.html>`_ library for
22842284
arbitrary precision correctly rounded decimal floating-point arithmetic [#]_.

Doc/library/multiprocessing.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ raising an exception.
832832

833833
One difference from other Python queue implementations, is that :mod:`multiprocessing`
834834
queues serializes all objects that are put into them using :mod:`pickle`.
835-
The object return by the get method is a re-created object that does not share memory
836-
with the original object.
835+
The object returned by the get method is a re-created object that does not share
836+
memory with the original object.
837837

838838
Note that one can also create a shared queue by using a manager object -- see
839839
:ref:`multiprocessing-managers`.
@@ -890,7 +890,7 @@ For an example of the usage of queues for interprocess communication see
890890
:ref:`multiprocessing-examples`.
891891

892892

893-
.. function:: Pipe([duplex])
893+
.. function:: Pipe(duplex=True)
894894

895895
Returns a pair ``(conn1, conn2)`` of
896896
:class:`~multiprocessing.connection.Connection` objects representing the
@@ -1577,12 +1577,22 @@ object -- see :ref:`multiprocessing-managers`.
15771577
A solitary difference from its close analog exists: its ``acquire`` method's
15781578
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.
15791579

1580+
1581+
.. method:: get_value()
1582+
1583+
Return the current value of semaphore.
1584+
1585+
Note that this may raise :exc:`NotImplementedError` on platforms like
1586+
macOS where ``sem_getvalue()`` is not implemented.
1587+
1588+
15801589
.. method:: locked()
15811590

15821591
Return a boolean indicating whether this object is locked right now.
15831592

15841593
.. versionadded:: 3.14
15851594

1595+
15861596
.. note::
15871597

15881598
On macOS, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with

Doc/library/socket.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,11 +2095,8 @@ to sockets.
20952095
Accepts any real number, not only integer or float.
20962096

20972097

2098-
.. method:: socket.setsockopt(level, optname, value: int)
2099-
.. method:: socket.setsockopt(level, optname, value: buffer)
2100-
:noindex:
2101-
.. method:: socket.setsockopt(level, optname, None, optlen: int)
2102-
:noindex:
2098+
.. method:: socket.setsockopt(level, optname, value: int | Buffer)
2099+
socket.setsockopt(level, optname, None, optlen: int)
21032100

21042101
.. index:: pair: module; struct
21052102

Doc/library/ssl.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,16 +2959,16 @@ of TLS/SSL. Some new TLS 1.3 features are not yet available.
29592959
Steve Kent
29602960

29612961
:rfc:`RFC 4086: Randomness Requirements for Security <4086>`
2962-
Donald E., Jeffrey I. Schiller
2962+
Donald E. Eastlake, Jeffrey I. Schiller, Steve Crocker
29632963

29642964
:rfc:`RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile <5280>`
2965-
D. Cooper
2965+
David Cooper et al.
29662966

29672967
:rfc:`RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2 <5246>`
2968-
T. Dierks et. al.
2968+
Tim Dierks and Eric Rescorla.
29692969

29702970
:rfc:`RFC 6066: Transport Layer Security (TLS) Extensions <6066>`
2971-
D. Eastlake
2971+
Donald E. Eastlake
29722972

29732973
`IANA TLS: Transport Layer Security (TLS) Parameters <https://www.iana.org/assignments/tls-parameters/tls-parameters.xml>`_
29742974
IANA

Doc/library/subprocess.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,9 @@ Instances of the :class:`Popen` class have the following methods:
831831

832832
If the process does not terminate after *timeout* seconds, a
833833
:exc:`TimeoutExpired` exception will be raised. Catching this exception and
834-
retrying communication will not lose any output.
834+
retrying communication will not lose any output. Supplying *input* to a
835+
subsequent post-timeout :meth:`communicate` call is in undefined behavior
836+
and may become an error in the future.
835837

836838
The child process is not killed if the timeout expires, so in order to
837839
cleanup properly a well-behaved application should kill the child process and
@@ -844,6 +846,11 @@ Instances of the :class:`Popen` class have the following methods:
844846
proc.kill()
845847
outs, errs = proc.communicate()
846848

849+
After a call to :meth:`~Popen.communicate` raises :exc:`TimeoutExpired`, do
850+
not call :meth:`~Popen.wait`. Use an additional :meth:`~Popen.communicate`
851+
call to finish handling pipes and populate the :attr:`~Popen.returncode`
852+
attribute.
853+
847854
.. note::
848855

849856
The data read is buffered in memory, so do not use this method if the data

Doc/library/xml.sax.handler.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ for the feature and property names.
9696

9797
.. data:: feature_external_ges
9898

99+
.. warning::
100+
101+
Enabling opens a vulnerability to
102+
`external entity attacks <https://en.wikipedia.org/wiki/XML_external_entity_attack>`_
103+
if the parser is used with user-provided XML content.
104+
Please reflect on your `threat model <https://en.wikipedia.org/wiki/Threat_model>`_
105+
before enabling this feature.
106+
99107
| value: ``"http://xml.org/sax/features/external-general-entities"``
100108
| true: Include all external general (text) entities.
101109
| false: Do not include external general entities.

Doc/library/zipfile.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ provides tools to create, read, write, append, and list a ZIP file. Any
1616
advanced use of this module will require an understanding of the format, as
1717
defined in `PKZIP Application Note`_.
1818

19-
This module does not currently handle multi-disk ZIP files.
19+
This module does not handle multipart ZIP files.
2020
It can handle ZIP files that use the ZIP64 extensions
2121
(that is ZIP files that are more than 4 GiB in size). It supports
22-
decryption of encrypted files in ZIP archives, but it currently cannot
22+
decryption of encrypted files in ZIP archives, but it cannot
2323
create an encrypted file. Decryption is extremely slow as it is
2424
implemented in native Python rather than C.
2525

@@ -175,7 +175,7 @@ The module defines the following items:
175175

176176
.. _zipfile-objects:
177177

178-
ZipFile Objects
178+
ZipFile objects
179179
---------------
180180

181181

@@ -248,7 +248,7 @@ ZipFile Objects
248248
.. note::
249249

250250
*metadata_encoding* is an instance-wide setting for the ZipFile.
251-
It is not currently possible to set this on a per-member basis.
251+
It is not possible to set this on a per-member basis.
252252

253253
This attribute is a workaround for legacy implementations which produce
254254
archives with names in the current locale encoding or code page (mostly
@@ -571,7 +571,7 @@ The following data attributes are also available:
571571

572572
.. _path-objects:
573573

574-
Path Objects
574+
Path objects
575575
------------
576576

577577
.. class:: Path(root, at='')
@@ -707,7 +707,7 @@ changes.
707707

708708
.. _pyzipfile-objects:
709709

710-
PyZipFile Objects
710+
PyZipFile objects
711711
-----------------
712712

713713
The :class:`PyZipFile` constructor takes the same parameters as the
@@ -784,7 +784,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
784784

785785
.. _zipinfo-objects:
786786

787-
ZipInfo Objects
787+
ZipInfo objects
788788
---------------
789789

790790
Instances of the :class:`ZipInfo` class are returned by the :meth:`.getinfo` and
@@ -954,7 +954,7 @@ Instances have the following methods and attributes:
954954
.. _zipfile-commandline:
955955
.. program:: zipfile
956956

957-
Command-Line Interface
957+
Command-line interface
958958
----------------------
959959

960960
The :mod:`zipfile` module provides a simple command-line interface to interact
@@ -1029,7 +1029,7 @@ From file itself
10291029
Decompression may fail due to incorrect password / CRC checksum / ZIP format or
10301030
unsupported compression method / decryption.
10311031

1032-
File System limitations
1032+
File system limitations
10331033
~~~~~~~~~~~~~~~~~~~~~~~
10341034

10351035
Exceeding limitations on different file systems can cause decompression failed.

0 commit comments

Comments
 (0)