Skip to content

Commit 3bfaec9

Browse files
Merge branch 'main' of https://github.com/python/cpython into nocr
2 parents 3774f5d + c5438fd commit 3bfaec9

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

+973
-708
lines changed

Doc/about.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
=====================
2-
About these documents
3-
=====================
1+
========================
2+
About this documentation
3+
========================
44

55

6-
These documents are generated from `reStructuredText`_ sources by `Sphinx`_, a
7-
document processor specifically written for the Python documentation.
6+
Python's documentation is generated from `reStructuredText`_ sources
7+
using `Sphinx`_, a documentation generator originally created for Python
8+
and now maintained as an independent project.
89

910
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
1011
.. _Sphinx: https://www.sphinx-doc.org/
@@ -20,14 +21,14 @@ volunteers are always welcome!
2021
Many thanks go to:
2122

2223
* Fred L. Drake, Jr., the creator of the original Python documentation toolset
23-
and writer of much of the content;
24+
and author of much of the content;
2425
* the `Docutils <https://docutils.sourceforge.io/>`_ project for creating
2526
reStructuredText and the Docutils suite;
2627
* Fredrik Lundh for his Alternative Python Reference project from which Sphinx
2728
got many good ideas.
2829

2930

30-
Contributors to the Python Documentation
31+
Contributors to the Python documentation
3132
----------------------------------------
3233

3334
Many people have contributed to the Python language, the Python standard

Doc/library/asyncio-task.rst

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,59 @@ Scheduling From Other Threads
10671067
This function is meant to be called from a different OS thread
10681068
than the one where the event loop is running. Example::
10691069

1070-
# Create a coroutine
1071-
coro = asyncio.sleep(1, result=3)
1072-
1073-
# Submit the coroutine to a given loop
1074-
future = asyncio.run_coroutine_threadsafe(coro, loop)
1075-
1076-
# Wait for the result with an optional timeout argument
1077-
assert future.result(timeout) == 3
1070+
def in_thread(loop: asyncio.AbstractEventLoop) -> None:
1071+
# Run some blocking IO
1072+
pathlib.Path("example.txt").write_text("hello world", encoding="utf8")
1073+
1074+
# Create a coroutine
1075+
coro = asyncio.sleep(1, result=3)
1076+
1077+
# Submit the coroutine to a given loop
1078+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1079+
1080+
# Wait for the result with an optional timeout argument
1081+
assert future.result(timeout=2) == 3
1082+
1083+
async def amain() -> None:
1084+
# Get the running loop
1085+
loop = asyncio.get_running_loop()
1086+
1087+
# Run something in a thread
1088+
await asyncio.to_thread(in_thread, loop)
1089+
1090+
It's also possible to run the other way around. Example::
1091+
1092+
@contextlib.contextmanager
1093+
def loop_in_thread() -> Generator[asyncio.AbstractEventLoop]:
1094+
loop_fut = concurrent.futures.Future[asyncio.AbstractEventLoop]()
1095+
stop_event = asyncio.Event()
1096+
1097+
async def main() -> None:
1098+
loop_fut.set_result(asyncio.get_running_loop())
1099+
await stop_event.wait()
1100+
1101+
with concurrent.futures.ThreadPoolExecutor(1) as tpe:
1102+
complete_fut = tpe.submit(asyncio.run, main())
1103+
for fut in concurrent.futures.as_completed((loop_fut, complete_fut)):
1104+
if fut is loop_fut:
1105+
loop = loop_fut.result()
1106+
try:
1107+
yield loop
1108+
finally:
1109+
loop.call_soon_threadsafe(stop_event.set)
1110+
else:
1111+
fut.result()
1112+
1113+
# Create a loop in another thread
1114+
with loop_in_thread() as loop:
1115+
# Create a coroutine
1116+
coro = asyncio.sleep(1, result=3)
1117+
1118+
# Submit the coroutine to a given loop
1119+
future = asyncio.run_coroutine_threadsafe(coro, loop)
1120+
1121+
# Wait for the result with an optional timeout argument
1122+
assert future.result(timeout=2) == 3
10781123

10791124
If an exception is raised in the coroutine, the returned Future
10801125
will be notified. It can also be used to cancel the task in

Doc/library/calendar.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
138138

139139
:class:`TextCalendar` instances have the following methods:
140140

141+
.. method:: formatweek(theweek, w=0)
142+
143+
Return a single week in a string with no newline. If *w* is provided, it
144+
specifies the width of the date columns, which are centered. Depends
145+
on the first weekday as specified in the constructor or set by the
146+
:meth:`setfirstweekday` method.
147+
148+
141149
.. method:: formatmonth(theyear, themonth, w=0, l=0)
142150

143151
Return a month's calendar in a multi-line string. If *w* is provided, it

Doc/library/urllib.request.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ The following classes are provided:
411411
:ref:`http-password-mgr` for information on the interface that must be
412412
supported.
413413

414+
.. versionchanged:: 3.14
415+
Added support for HTTP digest authentication algorithm ``SHA-256``.
416+
414417

415418
.. class:: HTTPDigestAuthHandler(password_mgr=None)
416419

Doc/library/zipfile.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ The module defines the following items:
8484
formerly protected :attr:`!_compresslevel`. The older protected name
8585
continues to work as a property for backwards compatibility.
8686

87+
88+
.. method:: _for_archive(archive)
89+
90+
Resolve the date_time, compression attributes, and external attributes
91+
to suitable defaults as used by :meth:`ZipFile.writestr`.
92+
93+
Returns self for chaining.
94+
95+
.. versionadded:: 3.14
96+
97+
8798
.. function:: is_zipfile(filename)
8899

89100
Returns ``True`` if *filename* is a valid ZIP file based on its magic number,

Doc/whatsnew/3.14.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ sys
614614
sys.monitoring
615615
--------------
616616

617-
Two new events are added: :monitoring-event:`BRANCH_LEFT` and
618-
:monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated.
617+
* Two new events are added: :monitoring-event:`BRANCH_LEFT` and
618+
:monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated.
619619

620620
tkinter
621621
-------
@@ -646,13 +646,29 @@ unittest
646646
(Contributed by Jacob Walls in :gh:`80958`.)
647647

648648

649+
urllib
650+
------
651+
652+
* Upgrade HTTP digest authentication algorithm for :mod:`urllib.request` by
653+
supporting SHA-256 digest authentication as specified in :rfc:`7616`.
654+
(Contributed by Calvin Bui in :gh:`128193`.)
655+
656+
649657
uuid
650658
----
651659

652660
* Add support for UUID version 8 via :func:`uuid.uuid8` as specified
653661
in :rfc:`9562`.
654662
(Contributed by Bénédikt Tran in :gh:`89083`.)
655663

664+
zipinfo
665+
-------
666+
667+
* Added :func:`ZipInfo._for_archive <zipfile.ZipInfo._for_archive>`
668+
to resolve suitable defaults for a :class:`~zipfile.ZipInfo` object
669+
as used by :func:`ZipFile.writestr <zipfile.ZipFile.writestr>`.
670+
671+
(Contributed by Bénédikt Tran in :gh:`123424`.)
656672

657673
.. Add improved modules above alphabetically, not here at the end.
658674

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InternalDocs/parser.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ an input string as its argument, and yields one of the following results:
5656

5757
Note that "failure" results do not imply that the program is incorrect, nor do
5858
they necessarily mean that the parsing has failed. Since the choice operator is
59-
ordered, a failure very often merely indicates "try the following option". A
59+
ordered, a failure very often merely indicates "try the following option". A
6060
direct implementation of a PEG parser as a recursive descent parser will present
6161
exponential time performance in the worst case, because PEG parsers have
6262
infinite lookahead (this means that they can consider an arbitrary number of
@@ -253,7 +253,7 @@ inside curly-braces, which specifies the return value of the alternative:
253253
If the action is omitted, a default action is generated:
254254

255255
- If there is a single name in the rule, it gets returned.
256-
- If there multiple names in the rule, a collection with all parsed
256+
- If there are multiple names in the rule, a collection with all parsed
257257
expressions gets returned (the type of the collection will be different
258258
in C and Python).
259259

@@ -447,7 +447,7 @@ parser (the one used by the interpreter) just execute:
447447
$ make regen-pegen
448448
```
449449

450-
using the `Makefile` in the main directory. If you are on Windows you can
450+
using the `Makefile` in the main directory. If you are on Windows you can
451451
use the Visual Studio project files to regenerate the parser or to execute:
452452

453453
```dos
@@ -539,7 +539,7 @@ memoization is used.
539539
The C parser used by Python is highly optimized and memoization can be expensive
540540
both in memory and time. Although the memory cost is obvious (the parser needs
541541
memory for storing previous results in the cache) the execution time cost comes
542-
for continuously checking if the given rule has a cache hit or not. In many
542+
from continuously checking if the given rule has a cache hit or not. In many
543543
situations, just parsing it again can be faster. Pegen **disables memoization
544544
by default** except for rules with the special marker `memo` after the rule
545545
name (and type, if present):
@@ -605,7 +605,7 @@ File "<stdin>", line 1
605605
SyntaxError: invalid syntax
606606
```
607607

608-
While soft keywords don't have this limitation if used in a context other the
608+
While soft keywords don't have this limitation if used in a context other than
609609
one where they are defined as keywords:
610610

611611
```pycon

Lib/copy.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ def copy(x):
6767

6868
cls = type(x)
6969

70-
copier = _copy_dispatch.get(cls)
71-
if copier:
72-
return copier(x)
70+
if cls in _copy_atomic_types:
71+
return x
72+
if cls in _copy_builtin_containers:
73+
return cls.copy(x)
74+
7375

7476
if issubclass(cls, type):
7577
# treat it as a regular class:
76-
return _copy_immutable(x)
78+
return x
7779

7880
copier = getattr(cls, "__copy__", None)
7981
if copier is not None:
@@ -98,23 +100,12 @@ def copy(x):
98100
return _reconstruct(x, None, *rv)
99101

100102

101-
_copy_dispatch = d = {}
102-
103-
def _copy_immutable(x):
104-
return x
105-
for t in (types.NoneType, int, float, bool, complex, str, tuple,
103+
_copy_atomic_types = {types.NoneType, int, float, bool, complex, str, tuple,
106104
bytes, frozenset, type, range, slice, property,
107105
types.BuiltinFunctionType, types.EllipsisType,
108106
types.NotImplementedType, types.FunctionType, types.CodeType,
109-
weakref.ref, super):
110-
d[t] = _copy_immutable
111-
112-
d[list] = list.copy
113-
d[dict] = dict.copy
114-
d[set] = set.copy
115-
d[bytearray] = bytearray.copy
116-
117-
del d, t
107+
weakref.ref, super}
108+
_copy_builtin_containers = {list, dict, set, bytearray}
118109

119110
def deepcopy(x, memo=None, _nil=[]):
120111
"""Deep copy operation on arbitrary Python objects.

0 commit comments

Comments
 (0)