Skip to content

Commit 768ba42

Browse files
committed
Merge remote-tracking branch 'cpython/main' into gh-99726
2 parents bbcc6ee + d8ab0a4 commit 768ba42

File tree

164 files changed

+5119
-2049
lines changed

Some content is hidden

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

164 files changed

+5119
-2049
lines changed

Doc/c-api/code.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,51 @@ bound into a function.
115115
the free variables. On error, ``NULL`` is returned and an exception is raised.
116116
117117
.. versionadded:: 3.11
118+
119+
.. c:function:: int PyCode_AddWatcher(PyCode_WatchCallback callback)
120+
121+
Register *callback* as a code object watcher for the current interpreter.
122+
Return an ID which may be passed to :c:func:`PyCode_ClearWatcher`.
123+
In case of error (e.g. no more watcher IDs available),
124+
return ``-1`` and set an exception.
125+
126+
.. versionadded:: 3.12
127+
128+
.. c:function:: int PyCode_ClearWatcher(int watcher_id)
129+
130+
Clear watcher identified by *watcher_id* previously returned from
131+
:c:func:`PyCode_AddWatcher` for the current interpreter.
132+
Return ``0`` on success, or ``-1`` and set an exception on error
133+
(e.g. if the given *watcher_id* was never registered.)
134+
135+
.. versionadded:: 3.12
136+
137+
.. c:type:: PyCodeEvent
138+
139+
Enumeration of possible code object watcher events:
140+
- ``PY_CODE_EVENT_CREATE``
141+
- ``PY_CODE_EVENT_DESTROY``
142+
143+
.. versionadded:: 3.12
144+
145+
.. c:type:: int (*PyCode_WatchCallback)(PyCodeEvent event, PyCodeObject* co)
146+
147+
Type of a code object watcher callback function.
148+
149+
If *event* is ``PY_CODE_EVENT_CREATE``, then the callback is invoked
150+
after `co` has been fully initialized. Otherwise, the callback is invoked
151+
before the destruction of *co* takes place, so the prior state of *co*
152+
can be inspected.
153+
154+
Users of this API should not rely on internal runtime implementation
155+
details. Such details may include, but are not limited to, the exact
156+
order and timing of creation and destruction of code objects. While
157+
changes in these details may result in differences observable by watchers
158+
(including whether a callback is invoked or not), it does not change
159+
the semantics of the Python code being executed.
160+
161+
If the callback returns with an exception set, it must return ``-1``; this
162+
exception will be printed as an unraisable exception using
163+
:c:func:`PyErr_WriteUnraisable`. Otherwise it should return ``0``.
164+
165+
.. versionadded:: 3.12

Doc/library/asyncio-eventloop.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ an event loop:
3333

3434
Return the running event loop in the current OS thread.
3535

36-
If there is no running event loop a :exc:`RuntimeError` is raised.
36+
Raise a :exc:`RuntimeError` if there is no running event loop.
37+
3738
This function can only be called from a coroutine or a callback.
3839

3940
.. versionadded:: 3.7
@@ -52,17 +53,19 @@ an event loop:
5253
:func:`get_running_loop` function is preferred to :func:`get_event_loop`
5354
in coroutines and callbacks.
5455

55-
Consider also using the :func:`asyncio.run` function instead of using
56-
lower level functions to manually create and close an event loop.
56+
As noted above, consider using the higher-level :func:`asyncio.run` function,
57+
instead of using these lower level functions to manually create and close an
58+
event loop.
5759

5860
.. deprecated:: 3.10
59-
Deprecation warning is emitted if there is no running event loop.
60-
In future Python releases, this function will be an alias of
61-
:func:`get_running_loop`.
61+
Emits a deprecation warning if there is no running event loop.
62+
In future Python releases, this function may become an alias of
63+
:func:`get_running_loop` and will accordingly raise a
64+
:exc:`RuntimeError` if there is no running event loop.
6265

6366
.. function:: set_event_loop(loop)
6467

65-
Set *loop* as a current event loop for the current OS thread.
68+
Set *loop* as the current event loop for the current OS thread.
6669

6770
.. function:: new_event_loop()
6871

Doc/library/base64.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,23 @@ The modern interface provides:
5353
Encode the :term:`bytes-like object` *s* using Base64 and return the encoded
5454
:class:`bytes`.
5555

56-
Optional *altchars* must be a :term:`bytes-like object` of at least
57-
length 2 (additional characters are ignored) which specifies an alternative
58-
alphabet for the ``+`` and ``/`` characters. This allows an application to e.g.
59-
generate URL or filesystem safe Base64 strings. The default is ``None``, for
60-
which the standard Base64 alphabet is used.
56+
Optional *altchars* must be a :term:`bytes-like object` of length 2 which
57+
specifies an alternative alphabet for the ``+`` and ``/`` characters.
58+
This allows an application to e.g. generate URL or filesystem safe Base64
59+
strings. The default is ``None``, for which the standard Base64 alphabet is used.
60+
61+
May assert or raise a a :exc:`ValueError` if the length of *altchars* is not 2. Raises a
62+
:exc:`TypeError` if *altchars* is not a :term:`bytes-like object`.
6163

6264

6365
.. function:: b64decode(s, altchars=None, validate=False)
6466

6567
Decode the Base64 encoded :term:`bytes-like object` or ASCII string
6668
*s* and return the decoded :class:`bytes`.
6769

68-
Optional *altchars* must be a :term:`bytes-like object` or ASCII string of
69-
at least length 2 (additional characters are ignored) which specifies the
70-
alternative alphabet used instead of the ``+`` and ``/`` characters.
70+
Optional *altchars* must be a :term:`bytes-like object` or ASCII string
71+
of length 2 which specifies the alternative alphabet used instead of the
72+
``+`` and ``/`` characters.
7173

7274
A :exc:`binascii.Error` exception is raised
7375
if *s* is incorrectly padded.
@@ -80,6 +82,7 @@ The modern interface provides:
8082

8183
For more information about the strict base64 check, see :func:`binascii.a2b_base64`
8284

85+
May assert or raise a :exc:`ValueError` if the length of *altchars* is not 2.
8386

8487
.. function:: standard_b64encode(s)
8588

Doc/library/dataclasses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Module contents
7979
class C:
8080
...
8181

82-
@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
82+
@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False,
83+
match_args=True, kw_only=False, slots=False, weakref_slot=False)
8384
class C:
8485
...
8586

Doc/library/enum.rst

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Data Types
194194

195195
.. method:: EnumType.__getitem__(cls, name)
196196

197-
Returns the Enum member in *cls* matching *name*, or raises an :exc:`KeyError`::
197+
Returns the Enum member in *cls* matching *name*, or raises a :exc:`KeyError`::
198198

199199
>>> Color['BLUE']
200200
<Color.BLUE: 3>
@@ -241,7 +241,7 @@ Data Types
241241

242242
.. note:: Enum member values
243243

244-
Member values can be anything: :class:`int`, :class:`str`, etc.. If
244+
Member values can be anything: :class:`int`, :class:`str`, etc. If
245245
the exact value is unimportant you may use :class:`auto` instances and an
246246
appropriate value will be chosen for you. See :class:`auto` for the
247247
details.
@@ -255,7 +255,7 @@ Data Types
255255
names will also be removed from the completed enumeration. See
256256
:ref:`TimePeriod <enum-time-period>` for an example.
257257

258-
.. method:: Enum.__call__(cls, value, names=None, \*, module=None, qualname=None, type=None, start=1, boundary=None)
258+
.. method:: Enum.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
259259

260260
This method is called in two different ways:
261261

@@ -272,8 +272,8 @@ Data Types
272272
:module: The name of the module the new Enum is created in.
273273
:qualname: The actual location in the module where this Enum can be found.
274274
:type: A mix-in type for the new Enum.
275-
:start: The first integer value for the Enum (used by :class:`auto`)
276-
:boundary: How to handle out-of-range values from bit operations (:class:`Flag` only)
275+
:start: The first integer value for the Enum (used by :class:`auto`).
276+
:boundary: How to handle out-of-range values from bit operations (:class:`Flag` only).
277277

278278
.. method:: Enum.__dir__(self)
279279

@@ -315,7 +315,7 @@ Data Types
315315
>>> PowersOfThree.SECOND.value
316316
6
317317

318-
.. method:: Enum.__init_subclass__(cls, \**kwds)
318+
.. method:: Enum.__init_subclass__(cls, **kwds)
319319

320320
A *classmethod* that is used to further configure subsequent subclasses.
321321
By default, does nothing.
@@ -373,7 +373,7 @@ Data Types
373373
.. method:: Enum.__format__(self)
374374

375375
Returns the string used for *format()* and *f-string* calls. By default,
376-
returns :meth:`__str__` returns, but can be overridden::
376+
returns :meth:`__str__` return value, but can be overridden::
377377

378378
>>> class OtherStyle(Enum):
379379
... ALTERNATE = auto()
@@ -552,11 +552,11 @@ Data Types
552552
Using :class:`auto` with :class:`Flag` results in integers that are powers
553553
of two, starting with ``1``.
554554

555-
.. versionchanged:: 3.11 The *repr()* of zero-valued flags has changed. It
555+
.. versionchanged:: 3.11 The *repr()* of zero-valued flags has changed. It
556556
is now::
557557

558-
>>> Color(0) # doctest: +SKIP
559-
<Color: 0>
558+
>>> Color(0) # doctest: +SKIP
559+
<Color: 0>
560560

561561
.. class:: IntFlag
562562

@@ -600,7 +600,7 @@ Data Types
600600
*replacement of existing constants* use-case. :meth:`~object.__format__` was
601601
already :meth:`!int.__format__` for that same reason.
602602

603-
Inversion of a :class:`!IntFlag` now returns a positive value that is the
603+
Inversion of an :class:`!IntFlag` now returns a positive value that is the
604604
union of all flags not in the given flag, rather than a negative value.
605605
This matches the existing :class:`Flag` behavior.
606606

@@ -612,7 +612,7 @@ Data Types
612612
* :meth:`!int.__str__` for :class:`IntEnum` and :class:`IntFlag`
613613
* :meth:`!str.__str__` for :class:`StrEnum`
614614

615-
Inherit from :class:`!ReprEnum` to keep the :class:`str() <str> / :func:`format`
615+
Inherit from :class:`!ReprEnum` to keep the :class:`str() <str>` / :func:`format`
616616
of the mixed-in data type instead of using the
617617
:class:`Enum`-default :meth:`str() <Enum.__str__>`.
618618

@@ -658,7 +658,7 @@ Data Types
658658
.. attribute:: NAMED_FLAGS
659659

660660
Ensure that any flag groups/masks contain only named flags -- useful when
661-
values are specified instead of being generated by :func:`auto`
661+
values are specified instead of being generated by :func:`auto`::
662662

663663
>>> from enum import Flag, verify, NAMED_FLAGS
664664
>>> @verify(NAMED_FLAGS)
@@ -804,6 +804,11 @@ Utilities and Decorators
804804
* ``THREE = [auto(), -3]`` will *not* work (``<auto instance>, -3`` is used to
805805
create the ``THREE`` enum member)
806806

807+
.. versionchanged:: 3.11.1
808+
809+
In prior versions, ``auto()`` had to be the only thing
810+
on the assignment line to work properly.
811+
807812
``_generate_next_value_`` can be overridden to customize the values used by
808813
*auto*.
809814

@@ -885,23 +890,23 @@ Notes
885890

886891
:class:`IntEnum`, :class:`StrEnum`, and :class:`IntFlag`
887892

888-
These three enum types are designed to be drop-in replacements for existing
889-
integer- and string-based values; as such, they have extra limitations:
893+
These three enum types are designed to be drop-in replacements for existing
894+
integer- and string-based values; as such, they have extra limitations:
890895

891-
- ``__str__`` uses the value and not the name of the enum member
896+
- ``__str__`` uses the value and not the name of the enum member
892897

893-
- ``__format__``, because it uses ``__str__``, will also use the value of
894-
the enum member instead of its name
898+
- ``__format__``, because it uses ``__str__``, will also use the value of
899+
the enum member instead of its name
895900

896-
If you do not need/want those limitations, you can either create your own
897-
base class by mixing in the ``int`` or ``str`` type yourself::
901+
If you do not need/want those limitations, you can either create your own
902+
base class by mixing in the ``int`` or ``str`` type yourself::
898903

899-
>>> from enum import Enum
900-
>>> class MyIntEnum(int, Enum):
901-
... pass
904+
>>> from enum import Enum
905+
>>> class MyIntEnum(int, Enum):
906+
... pass
902907

903908
or you can reassign the appropriate :meth:`str`, etc., in your enum::
904909

905-
>>> from enum import IntEnum
906-
>>> class MyIntEnum(IntEnum):
907-
... __str__ = IntEnum.__str__
910+
>>> from enum import IntEnum
911+
>>> class MyIntEnum(IntEnum):
912+
... __str__ = IntEnum.__str__

Doc/library/fnmatch.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ patterns.
4848

4949
Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
5050
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
51-
:func:`fnmatchcase`, :func:`filter`.
51+
:func:`fnmatchcase`, :func:`.filter`.
5252

5353
.. function:: fnmatch(filename, pattern)
5454

Doc/library/http.server.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,10 @@ Security Considerations
512512
:class:`SimpleHTTPRequestHandler` will follow symbolic links when handling
513513
requests, this makes it possible for files outside of the specified directory
514514
to be served.
515+
516+
Earlier versions of Python did not scrub control characters from the
517+
log messages emitted to stderr from ``python -m http.server`` or the
518+
default :class:`BaseHTTPRequestHandler` ``.log_message``
519+
implementation. This could allow to remote clients connecting to your
520+
server to send nefarious control codes to your terminal.
521+

Doc/library/re.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,16 +1565,22 @@ search() vs. match()
15651565

15661566
.. sectionauthor:: Fred L. Drake, Jr. <[email protected]>
15671567

1568-
Python offers two different primitive operations based on regular expressions:
1569-
:func:`re.match` checks for a match only at the beginning of the string, while
1570-
:func:`re.search` checks for a match anywhere in the string (this is what Perl
1571-
does by default).
1568+
Python offers different primitive operations based on regular expressions:
1569+
1570+
+ :func:`re.match` checks for a match only at the beginning of the string
1571+
+ :func:`re.search` checks for a match anywhere in the string
1572+
(this is what Perl does by default)
1573+
+ :func:`re.fullmatch` checks for entire string to be a match
1574+
15721575

15731576
For example::
15741577

15751578
>>> re.match("c", "abcdef") # No match
15761579
>>> re.search("c", "abcdef") # Match
15771580
<re.Match object; span=(2, 3), match='c'>
1581+
>>> re.fullmatch("p.*n", "python") # Match
1582+
<re.Match object; span=(0, 6), match='python'>
1583+
>>> re.fullmatch("r.*n", "python") # No match
15781584

15791585
Regular expressions beginning with ``'^'`` can be used with :func:`search` to
15801586
restrict the match at the beginning of the string::
@@ -1588,8 +1594,8 @@ Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
15881594
beginning of the string, whereas using :func:`search` with a regular expression
15891595
beginning with ``'^'`` will match at the beginning of each line. ::
15901596

1591-
>>> re.match('X', 'A\nB\nX', re.MULTILINE) # No match
1592-
>>> re.search('^X', 'A\nB\nX', re.MULTILINE) # Match
1597+
>>> re.match("X", "A\nB\nX", re.MULTILINE) # No match
1598+
>>> re.search("^X", "A\nB\nX", re.MULTILINE) # Match
15931599
<re.Match object; span=(4, 5), match='X'>
15941600

15951601

Doc/library/socketserver.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ synchronous servers of four types::
9696

9797
Note that :class:`UnixDatagramServer` derives from :class:`UDPServer`, not from
9898
:class:`UnixStreamServer` --- the only difference between an IP and a Unix
99-
stream server is the address family, which is simply repeated in both Unix
100-
server classes.
99+
server is the address family.
101100

102101

103102
.. class:: ForkingMixIn
@@ -431,11 +430,8 @@ Request Handler Objects
431430
The :attr:`self.rfile` and :attr:`self.wfile` attributes can be
432431
read or written, respectively, to get the request data or return data
433432
to the client.
434-
435-
The :attr:`rfile` attributes of both classes support the
436-
:class:`io.BufferedIOBase` readable interface, and
437-
:attr:`DatagramRequestHandler.wfile` supports the
438-
:class:`io.BufferedIOBase` writable interface.
433+
The :attr:`!rfile` attributes support the :class:`io.BufferedIOBase` readable interface,
434+
and :attr:`!wfile` attributes support the :class:`!io.BufferedIOBase` writable interface.
439435

440436
.. versionchanged:: 3.6
441437
:attr:`StreamRequestHandler.wfile` also supports the

Doc/library/sqlite3.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Module functions
292292
By default (``0``), type detection is disabled.
293293

294294
:param isolation_level:
295+
Control legacy transaction handling behaviour.
295296
See :attr:`Connection.isolation_level` and
296297
:ref:`sqlite3-transaction-control-isolation-level` for more information.
297298
Can be ``"DEFERRED"`` (default), ``"EXCLUSIVE"`` or ``"IMMEDIATE"``;
@@ -325,6 +326,7 @@ Module functions
325326
enabling various :ref:`sqlite3-uri-tricks`.
326327

327328
:param autocommit:
329+
Control :pep:`249` transaction handling behaviour.
328330
See :attr:`Connection.autocommit` and
329331
:ref:`sqlite3-transaction-control-autocommit` for more information.
330332
*autocommit* currently defaults to
@@ -2468,9 +2470,9 @@ which implies :pep:`249`-compliant transaction control.
24682470
This means:
24692471

24702472
* :mod:`!sqlite3` ensures that a transaction is always open,
2471-
so :meth:`Connection.commit` and :meth:`Connection.rollback`
2472-
will implicitly open a new transaction immediately after closing
2473-
the pending one.
2473+
so :func:`connect`, :meth:`Connection.commit`, and :meth:`Connection.rollback`
2474+
will implicitly open a new transaction
2475+
(immediately after closing the pending one, for the latter two).
24742476
:mod:`!sqlite3` uses ``BEGIN DEFERRED`` statements when opening transactions.
24752477
* Transactions should be committed explicitly using :meth:`!commit`.
24762478
* Transactions should be rolled back explicitly using :meth:`!rollback`.

0 commit comments

Comments
 (0)