Skip to content

Commit fcb7a6d

Browse files
authored
Merge pull request #501 from python/main
Sync Fork from Upstream Repo
2 parents 6310bd4 + 4aa63d6 commit fcb7a6d

30 files changed

Lines changed: 258 additions & 110 deletions

Doc/c-api/stable.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ embedding Python.)
4141

4242
.. c:macro:: Py_LIMITED_API
4343
44-
Define this macro ``Py_LIMITED_API`` before including ``Python.h`` to
45-
opt in to only use the Limited API.
46-
47-
Defining ``Py_LIMITED_API`` to ``3`` will limit the available API so that
48-
the extension will work without recompilation with all Python 3.x releases
49-
(x>=2) on the particular :ref:`platform <stable-abi-platform>`.
50-
51-
Defining ``Py_LIMITED_API`` to a value of :c:data:`PY_VERSION_HEX` will
52-
limit the available API so that the extension will work without
53-
recompilation with all Python 3 releases from the specified one.
54-
This will allow using additional API introduced up to this version,
55-
but the extension will lose compatibility with earlier Python versions.
44+
Define this macro before including ``Python.h`` to opt in to only use
45+
the Limited API, and to select the Limited API version.
46+
47+
Define ``Py_LIMITED_API`` to the value of :c:data:`PY_VERSION_HEX`
48+
corresponding to the lowest Python version your extension supports.
49+
The extension will work without recompilation with all Python 3 releases
50+
from the specified one onward, and can use Limited API introduced up to that
51+
version.
52+
5653
Rather than using the ``PY_VERSION_HEX`` macro directly, hardcode a minimum
5754
minor version (e.g. ``0x030A0000`` for Python 3.10) for stability when
5855
compiling with future Python versions.
5956

57+
You can also define ``Py_LIMITED_API`` to ``3``. This works the same as
58+
``0x03020000`` (Python 3.2, the version that introduced Limited API).
59+
6060
On Windows, extensions that use the Stable ABI should be linked against
6161
``python3.dll`` rather than a version-specific library such as
6262
``python39.dll``.

Doc/library/asyncio-protocol.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ factories passed to the :meth:`loop.create_datagram_endpoint` method.
683683
Subprocess Protocols
684684
--------------------
685685

686-
Datagram Protocol instances should be constructed by protocol
686+
Subprocess Protocol instances should be constructed by protocol
687687
factories passed to the :meth:`loop.subprocess_exec` and
688688
:meth:`loop.subprocess_shell` methods.
689689

Doc/library/asyncio-task.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,32 +358,35 @@ Running Tasks Concurrently
358358
async def factorial(name, number):
359359
f = 1
360360
for i in range(2, number + 1):
361-
print(f"Task {name}: Compute factorial({i})...")
361+
print(f"Task {name}: Compute factorial({number}), currently i={i}...")
362362
await asyncio.sleep(1)
363363
f *= i
364364
print(f"Task {name}: factorial({number}) = {f}")
365+
return f
365366

366367
async def main():
367368
# Schedule three calls *concurrently*:
368-
await asyncio.gather(
369+
L = await asyncio.gather(
369370
factorial("A", 2),
370371
factorial("B", 3),
371372
factorial("C", 4),
372373
)
374+
print(L)
373375

374376
asyncio.run(main())
375377

376378
# Expected output:
377379
#
378-
# Task A: Compute factorial(2)...
379-
# Task B: Compute factorial(2)...
380-
# Task C: Compute factorial(2)...
380+
# Task A: Compute factorial(2), currently i=2...
381+
# Task B: Compute factorial(3), currently i=2...
382+
# Task C: Compute factorial(4), currently i=2...
381383
# Task A: factorial(2) = 2
382-
# Task B: Compute factorial(3)...
383-
# Task C: Compute factorial(3)...
384+
# Task B: Compute factorial(3), currently i=3...
385+
# Task C: Compute factorial(4), currently i=3...
384386
# Task B: factorial(3) = 6
385-
# Task C: Compute factorial(4)...
387+
# Task C: Compute factorial(4), currently i=4...
386388
# Task C: factorial(4) = 24
389+
# [2, 6, 24]
387390

388391
.. note::
389392
If *return_exceptions* is False, cancelling gather() after it

Doc/library/cgi.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ algorithms implemented in this module in other circumstances.
316316
.. function:: test()
317317

318318
Robust test CGI script, usable as main program. Writes minimal HTTP headers and
319-
formats all information provided to the script in HTML form.
319+
formats all information provided to the script in HTML format.
320320

321321

322322
.. function:: print_environ()
@@ -346,8 +346,8 @@ Caring about security
346346

347347
.. index:: pair: CGI; security
348348

349-
There's one important rule: if you invoke an external program (via the
350-
:func:`os.system` or :func:`os.popen` functions. or others with similar
349+
There's one important rule: if you invoke an external program (via
350+
:func:`os.system`, :func:`os.popen` or other functions with similar
351351
functionality), make very sure you don't pass arbitrary strings received from
352352
the client to the shell. This is a well-known security hole whereby clever
353353
hackers anywhere on the Web can exploit a gullible CGI script to invoke
@@ -424,7 +424,7 @@ above on installing your CGI script carefully can save you a lot of time. If
424424
you wonder whether you have understood the installation procedure correctly, try
425425
installing a copy of this module file (:file:`cgi.py`) as a CGI script. When
426426
invoked as a script, the file will dump its environment and the contents of the
427-
form in HTML form. Give it the right mode etc, and send it a request. If it's
427+
form in HTML format. Give it the right mode etc., and send it a request. If it's
428428
installed in the standard :file:`cgi-bin` directory, it should be possible to
429429
send it a request by entering a URL into your browser of the form:
430430

Doc/library/enum.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ Data Types
575575
>>> KeepFlag(2**2 + 2**4)
576576
KeepFlag.BLUE|0x10
577577

578+
.. versionadded:: 3.10 ``FlagBoundary``
579+
578580

579581
Utilites and Decorators
580582
-----------------------
@@ -598,6 +600,7 @@ Utilites and Decorators
598600
also injects the members, and their aliases, into the the global namespace
599601
they were defined in.
600602

603+
.. versionadded:: 3.10
601604

602605
.. decorator:: property
603606

@@ -610,6 +613,8 @@ Utilites and Decorators
610613
*Enum* class, and *Enum* subclasses can define members with the
611614
names ``value`` and ``name``.
612615

616+
.. versionadded:: 3.10
617+
613618
.. decorator:: unique
614619

615620
A :keyword:`class` decorator specifically for enumerations. It searches an

Doc/library/numbers.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ The numeric tower
2727
Subclasses of this type describe complex numbers and include the operations
2828
that work on the built-in :class:`complex` type. These are: conversions to
2929
:class:`complex` and :class:`bool`, :attr:`.real`, :attr:`.imag`, ``+``,
30-
``-``, ``*``, ``/``, :func:`abs`, :meth:`conjugate`, ``==``, and ``!=``. All
31-
except ``-`` and ``!=`` are abstract.
30+
``-``, ``*``, ``/``, ``**``, :func:`abs`, :meth:`conjugate`, ``==``, and
31+
``!=``. All except ``-`` and ``!=`` are abstract.
3232

3333
.. attribute:: real
3434

@@ -76,8 +76,9 @@ The numeric tower
7676

7777
Subtypes :class:`Rational` and adds a conversion to :class:`int`. Provides
7878
defaults for :func:`float`, :attr:`~Rational.numerator`, and
79-
:attr:`~Rational.denominator`. Adds abstract methods for ``**`` and
80-
bit-string operations: ``<<``, ``>>``, ``&``, ``^``, ``|``, ``~``.
79+
:attr:`~Rational.denominator`. Adds abstract methods for :func:`pow` with
80+
modulus and bit-string operations: ``<<``, ``>>``, ``&``, ``^``, ``|``,
81+
``~``.
8182

8283

8384
Notes for type implementors

Doc/library/zipfile.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,27 @@ Path objects are traversable using the ``/`` operator or ``joinpath``.
521521
Return ``True`` if the current context references a file or
522522
directory in the zip file.
523523

524+
.. data:: Path.suffix
525+
526+
The file extension of the final component.
527+
528+
.. versionadded:: 3.11
529+
Added :data:`Path.suffix` property.
530+
531+
.. data:: Path.stem
532+
533+
The final path component, without its suffix.
534+
535+
.. versionadded:: 3.11
536+
Added :data:`Path.stem` property.
537+
538+
.. data:: Path.suffixes
539+
540+
A list of the path’s file extensions.
541+
542+
.. versionadded:: 3.11
543+
Added :data:`Path.suffixes` property.
544+
524545
.. method:: Path.read_text(*, **)
525546

526547
Read the current file as unicode text. Positional and

Doc/reference/compound_stmts.rst

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ is found that matches the exception. An expression-less except clause, if
254254
present, must be last; it matches any exception. For an except clause with an
255255
expression, that expression is evaluated, and the clause matches the exception
256256
if the resulting object is "compatible" with the exception. An object is
257-
compatible with an exception if it is the class or a base class of the exception
257+
compatible with an exception if the object is the class or a base class of the exception
258258
object, or a tuple containing an item that is the class or a base class of
259259
the exception object.
260260

@@ -822,7 +822,7 @@ and binds no name. Syntax:
822822

823823
``_`` is a :ref:`soft keyword <soft-keywords>` within any pattern,
824824
but only within patterns. It is an identifier, as usual, even within
825-
``match`` headers, ``guards``, and ``case`` blocks.
825+
``match`` subject expressions, ``guard``\ s, and ``case`` blocks.
826826

827827
In simple terms, ``_`` will always succeed.
828828

@@ -900,8 +900,8 @@ sequence pattern.
900900
The following is the logical flow for matching a sequence pattern against a
901901
subject value:
902902

903-
#. If the subject value is not an instance of a
904-
:class:`collections.abc.Sequence` the sequence pattern fails.
903+
#. If the subject value is not a sequence [#]_, the sequence pattern
904+
fails.
905905

906906
#. If the subject value is an instance of ``str``, ``bytes`` or ``bytearray``
907907
the sequence pattern fails.
@@ -943,7 +943,7 @@ subject value:
943943
In simple terms ``[P1, P2, P3,`` ... ``, P<N>]`` matches only if all the following
944944
happens:
945945

946-
* ``isinstance(<subject>, collections.abc.Sequence)``
946+
* check ``<subject>`` is a sequence
947947
* ``len(subject) == <N>``
948948
* ``P1`` matches ``<subject>[0]`` (note that this match can also bind names)
949949
* ``P2`` matches ``<subject>[1]`` (note that this match can also bind names)
@@ -975,8 +975,7 @@ runtime error and will raise :exc:`ValueError`.)
975975
The following is the logical flow for matching a mapping pattern against a
976976
subject value:
977977

978-
#. If the subject value is not an instance of :class:`collections.abc.Mapping`,
979-
the mapping pattern fails.
978+
#. If the subject value is not a mapping [#]_,the mapping pattern fails.
980979

981980
#. If every key given in the mapping pattern is present in the subject mapping,
982981
and the pattern for each key matches the corresponding item of the subject
@@ -993,7 +992,7 @@ subject value:
993992
In simple terms ``{KEY1: P1, KEY2: P2, ... }`` matches only if all the following
994993
happens:
995994

996-
* ``isinstance(<subject>, collections.abc.Mapping)``
995+
* check ``<subject>`` is a mapping
997996
* ``KEY1 in <subject>``
998997
* ``P1`` matches ``<subject>[KEY1]``
999998
* ... and so on for the corresponding KEY/pattern pair.
@@ -1526,6 +1525,35 @@ body of a coroutine function.
15261525
there is a :keyword:`finally` clause which happens to raise another
15271526
exception. That new exception causes the old one to be lost.
15281527
1528+
.. [#] In pattern matching, a sequence is defined as one of the following:
1529+
1530+
* a class that inherits from :class:`collections.abc.Sequence`
1531+
* a Python class that has been registered as :class:`collections.abc.Sequence`
1532+
* a builtin class that has its (CPython) :data:`Py_TPFLAGS_SEQUENCE` bit set
1533+
* a class that inherits from any of the above
1534+
1535+
The following standard library classes are sequences:
1536+
1537+
* :class:`array.array`
1538+
* :class:`collections.deque`
1539+
* :class:`list`
1540+
* :class:`memoryview`
1541+
* :class:`range`
1542+
* :class:`tuple`
1543+
1544+
.. note:: Subject values of type ``str``, ``bytes``, and ``bytearray``
1545+
do not match sequence patterns.
1546+
1547+
.. [#] In pattern matching, a mapping is defined as one of the following:
1548+
1549+
* a class that inherits from :class:`collections.abc.Mapping`
1550+
* a Python class that has been registered as :class:`collections.abc.Mapping`
1551+
* a builtin class that has its (CPython) :data:`Py_TPFLAGS_MAPPING` bit set
1552+
* a class that inherits from any of the above
1553+
1554+
The standard library classes :class:`dict` and :class:`types.MappingProxyType`
1555+
are mappings.
1556+
15291557
.. [#] A string literal appearing as the first statement in the function body is
15301558
transformed into the function's ``__doc__`` attribute and therefore the
15311559
function's :term:`docstring`.

Doc/reference/simple_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ The :keyword:`!import` statement
734734
: ("," `identifier` ["as" `identifier`])*
735735
: | "from" `relative_module` "import" "(" `identifier` ["as" `identifier`]
736736
: ("," `identifier` ["as" `identifier`])* [","] ")"
737-
: | "from" `module` "import" "*"
737+
: | "from" `relative_module` "import" "*"
738738
module: (`identifier` ".")* `identifier`
739739
relative_module: "."* `module` | "."+
740740

Doc/tutorial/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ operator; to calculate the remainder you can use ``%``::
7373
5
7474
>>> 17 % 3 # the % operator returns the remainder of the division
7575
2
76-
>>> 5 * 3 + 2 # result * divisor + remainder
76+
>>> 5 * 3 + 2 # floored quotient * divisor + remainder
7777
17
7878

7979
With Python, it is possible to use the ``**`` operator to calculate powers [#]_::

0 commit comments

Comments
 (0)