Skip to content

Commit afba682

Browse files
authored
Merge branch 'main' into add_return_none
2 parents a987bea + d54b8d8 commit afba682

Some content is hidden

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

47 files changed

+2705
-535
lines changed

Doc/bugs.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ If you find a bug in this documentation or would like to propose an improvement,
1919
please submit a bug report on the :ref:`tracker <using-the-tracker>`. If you
2020
have a suggestion on how to fix it, include that as well.
2121

22+
You can also open a discussion item on our
23+
`Documentation Discourse forum <https://discuss.python.org/c/documentation/26>`_.
24+
2225
If you're short on time, you can also email documentation bug reports to
2326
docs@python.org (behavioral bugs can be sent to python-list@python.org).
2427
'docs@' is a mailing list run by volunteers; your request will be noticed,

Doc/library/asyncio-eventloop.rst

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,24 @@ Running and stopping the loop
186186
.. coroutinemethod:: loop.shutdown_default_executor(timeout=None)
187187

188188
Schedule the closure of the default executor and wait for it to join all of
189-
the threads in the :class:`ThreadPoolExecutor`. After calling this method, a
190-
:exc:`RuntimeError` will be raised if :meth:`loop.run_in_executor` is called
191-
while using the default executor.
189+
the threads in the :class:`~concurrent.futures.ThreadPoolExecutor`.
190+
Once this method has been called,
191+
using the default executor with :meth:`loop.run_in_executor`
192+
will raise a :exc:`RuntimeError`.
192193

193-
The *timeout* parameter specifies the amount of time the executor will
194-
be given to finish joining. The default value is ``None``, which means the
195-
executor will be given an unlimited amount of time.
194+
The *timeout* parameter specifies the amount of time
195+
(in :class:`float` seconds) the executor will be given to finish joining.
196+
With the default, ``None``,
197+
the executor is allowed an unlimited amount of time.
196198

197-
If the timeout duration is reached, a warning is emitted and executor is
198-
terminated without waiting for its threads to finish joining.
199+
If the *timeout* is reached, a :exc:`RuntimeWarning` is emitted
200+
and the default executor is terminated
201+
without waiting for its threads to finish joining.
199202

200-
Note that there is no need to call this function when
201-
:func:`asyncio.run` is used.
203+
.. note::
204+
205+
Do not call this method when using :func:`asyncio.run`,
206+
as the latter handles default executor shutdown automatically.
202207

203208
.. versionadded:: 3.9
204209

@@ -213,22 +218,23 @@ Scheduling callbacks
213218
Schedule the *callback* :term:`callback` to be called with
214219
*args* arguments at the next iteration of the event loop.
215220

221+
Return an instance of :class:`asyncio.Handle`,
222+
which can be used later to cancel the callback.
223+
216224
Callbacks are called in the order in which they are registered.
217225
Each callback will be called exactly once.
218226

219-
An optional keyword-only *context* argument allows specifying a
227+
The optional keyword-only *context* argument specifies a
220228
custom :class:`contextvars.Context` for the *callback* to run in.
221-
The current context is used when no *context* is provided.
222-
223-
An instance of :class:`asyncio.Handle` is returned, which can be
224-
used later to cancel the callback.
229+
Callbacks use the current context when no *context* is provided.
225230

226-
This method is not thread-safe.
231+
Unlike :meth:`call_soon_threadsafe`, this method is not thread-safe.
227232

228233
.. method:: loop.call_soon_threadsafe(callback, *args, context=None)
229234

230-
A thread-safe variant of :meth:`call_soon`. Must be used to
231-
schedule callbacks *from another thread*.
235+
A thread-safe variant of :meth:`call_soon`. When scheduling callbacks from
236+
another thread, this function *must* be used, since :meth:`call_soon` is not
237+
thread-safe.
232238

233239
Raises :exc:`RuntimeError` if called on a loop that's been closed.
234240
This can happen on a secondary thread when the main application is

Doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sphinx==4.5.0
88
blurb
99

1010
sphinx-lint==0.6.7
11-
sphinxext-opengraph>=0.7.1
11+
sphinxext-opengraph==0.7.5
1212

1313
# The theme used by the documentation is stored separately, so we need
1414
# to install that as well.

Doc/whatsnew/3.12.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ APIs:
479479
* :class:`webbrowser.MacOSX` (:gh:`86421`)
480480

481481
Pending Removal in Python 3.14
482-
==============================
482+
------------------------------
483483

484484
* Deprecated the following :mod:`importlib.abc` classes, scheduled for removal in
485485
Python 3.14:

Lib/enum.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,12 +1429,11 @@ def _missing_(cls, value):
14291429
% (cls.__name__, value, unknown, bin(unknown))
14301430
)
14311431
# normal Flag?
1432-
__new__ = getattr(cls, '__new_member__', None)
1433-
if cls._member_type_ is object and not __new__:
1432+
if cls._member_type_ is object:
14341433
# construct a singleton enum pseudo-member
14351434
pseudo_member = object.__new__(cls)
14361435
else:
1437-
pseudo_member = (__new__ or cls._member_type_.__new__)(cls, value)
1436+
pseudo_member = cls._member_type_.__new__(cls, value)
14381437
if not hasattr(pseudo_member, '_value_'):
14391438
pseudo_member._value_ = value
14401439
if member_value:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import unittest
2+
3+
from test.support import import_helper
4+
5+
6+
# Skip this test if the _testcapi module isn't available.
7+
_testcapi = import_helper.import_module('_testcapi')
8+
9+
10+
class PyEval_EvalCodeExTests(unittest.TestCase):
11+
12+
def test_simple(self):
13+
def f():
14+
return a
15+
16+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, dict(a=1)), 1)
17+
18+
# Need to force the compiler to use LOAD_NAME
19+
# def test_custom_locals(self):
20+
# def f():
21+
# return
22+
23+
def test_with_args(self):
24+
def f(a, b, c):
25+
return a
26+
27+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (1, 2, 3)), 1)
28+
29+
def test_with_kwargs(self):
30+
def f(a, b, c):
31+
return a
32+
33+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), dict(a=1, b=2, c=3)), 1)
34+
35+
def test_with_default(self):
36+
def f(a):
37+
return a
38+
39+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (1,)), 1)
40+
41+
def test_with_kwarg_default(self):
42+
def f(*, a):
43+
return a
44+
45+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), dict(a=1)), 1)
46+
47+
def test_with_closure(self):
48+
a = 1
49+
def f():
50+
return a
51+
52+
self.assertEqual(_testcapi.eval_code_ex(f.__code__, {}, {}, (), {}, (), {}, f.__closure__), 1)
53+
54+
55+
if __name__ == "__main__":
56+
unittest.main()

Lib/test/test_capi/test_misc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,9 @@ def callback():
14131413
ret = assert_python_ok('-X', 'tracemalloc', '-c', code)
14141414
self.assertIn(b'callback called', ret.out)
14151415

1416+
def test_gilstate_matches_current(self):
1417+
_testcapi.test_current_tstate_matches()
1418+
14161419

14171420
class Test_testcapi(unittest.TestCase):
14181421
locals().update((name, getattr(_testcapi, name))

Lib/test/test_ctypes/test_pep3118.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ class PackedPoint(Structure):
8787
_fields_ = [("x", c_long), ("y", c_long)]
8888

8989
class PointMidPad(Structure):
90-
_fields_ = [("x", c_byte), ("y", c_uint64)]
90+
_fields_ = [("x", c_byte), ("y", c_uint)]
9191

9292
class PackedPointMidPad(Structure):
9393
_pack_ = 2
9494
_fields_ = [("x", c_byte), ("y", c_uint64)]
9595

9696
class PointEndPad(Structure):
97-
_fields_ = [("x", c_uint64), ("y", c_byte)]
97+
_fields_ = [("x", c_uint), ("y", c_byte)]
9898

9999
class PackedPointEndPad(Structure):
100100
_pack_ = 2
@@ -199,14 +199,14 @@ class Complete(Structure):
199199

200200
## structures and unions
201201

202-
(Point2, "T{<l:x:<l:y:}".replace('l', s_long), (), Point2),
203-
(Point, "T{<l:x:<l:y:}".replace('l', s_long), (), Point),
204-
(PackedPoint, "T{<l:x:<l:y:}".replace('l', s_long), (), PackedPoint),
205-
(PointMidPad, "T{<b:x:7x<Q:y:}", (), PointMidPad),
206-
(PackedPointMidPad, "T{<b:x:x<Q:y:}", (), PackedPointMidPad),
207-
(PointEndPad, "T{<Q:x:<b:y:7x}", (), PointEndPad),
208-
(PackedPointEndPad, "T{<Q:x:<b:y:x}", (), PackedPointEndPad),
209-
(EmptyStruct, "T{}", (), EmptyStruct),
202+
(Point2, "T{<l:x:<l:y:}".replace('l', s_long), (), Point2),
203+
(Point, "T{<l:x:<l:y:}".replace('l', s_long), (), Point),
204+
(PackedPoint, "T{<l:x:<l:y:}".replace('l', s_long), (), PackedPoint),
205+
(PointMidPad, "T{<b:x:3x<I:y:}".replace('I', s_uint), (), PointMidPad),
206+
(PackedPointMidPad, "T{<b:x:x<Q:y:}", (), PackedPointMidPad),
207+
(PointEndPad, "T{<I:x:<b:y:3x}".replace('I', s_uint), (), PointEndPad),
208+
(PackedPointEndPad, "T{<Q:x:<b:y:x}", (), PackedPointEndPad),
209+
(EmptyStruct, "T{}", (), EmptyStruct),
210210
# the pep doesn't support unions
211211
(aUnion, "B", (), aUnion),
212212
# structure with sub-arrays

Lib/test/test_enum.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,46 @@ class NTEnum(Enum):
28552855
[TTuple(id=0, a=0, blist=[]), TTuple(id=1, a=2, blist=[4]), TTuple(id=2, a=4, blist=[0, 1, 2])],
28562856
)
28572857

2858+
def test_flag_with_custom_new(self):
2859+
class FlagFromChar(IntFlag):
2860+
def __new__(cls, c):
2861+
value = 1 << c
2862+
self = int.__new__(cls, value)
2863+
self._value_ = value
2864+
return self
2865+
#
2866+
a = ord('a')
2867+
#
2868+
self.assertEqual(FlagFromChar.a, 158456325028528675187087900672)
2869+
self.assertEqual(FlagFromChar.a|1, 158456325028528675187087900673)
2870+
#
2871+
#
2872+
class FlagFromChar(Flag):
2873+
def __new__(cls, c):
2874+
value = 1 << c
2875+
self = object.__new__(cls)
2876+
self._value_ = value
2877+
return self
2878+
#
2879+
a = ord('a')
2880+
z = 1
2881+
#
2882+
self.assertEqual(FlagFromChar.a.value, 158456325028528675187087900672)
2883+
self.assertEqual((FlagFromChar.a|FlagFromChar.z).value, 158456325028528675187087900674)
2884+
#
2885+
#
2886+
class FlagFromChar(int, Flag, boundary=KEEP):
2887+
def __new__(cls, c):
2888+
value = 1 << c
2889+
self = int.__new__(cls, value)
2890+
self._value_ = value
2891+
return self
2892+
#
2893+
a = ord('a')
2894+
#
2895+
self.assertEqual(FlagFromChar.a, 158456325028528675187087900672)
2896+
self.assertEqual(FlagFromChar.a|1, 158456325028528675187087900673)
2897+
28582898
class TestOrder(unittest.TestCase):
28592899
"test usage of the `_order_` attribute"
28602900

Lib/test/test_hashlib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from test.support import _4G, bigmemtest
2323
from test.support.import_helper import import_fresh_module
2424
from test.support import os_helper
25+
from test.support import requires_resource
2526
from test.support import threading_helper
2627
from test.support import warnings_helper
2728
from http.client import HTTPException
@@ -354,6 +355,15 @@ def test_large_update(self):
354355
self.assertEqual(m1.digest(*args), m4_copy.digest(*args))
355356
self.assertEqual(m4.digest(*args), m4_digest)
356357

358+
@requires_resource('cpu')
359+
def test_sha256_update_over_4gb(self):
360+
zero_1mb = b"\0" * 1024 * 1024
361+
h = hashlib.sha256()
362+
for i in range(0, 4096):
363+
h.update(zero_1mb)
364+
h.update(b"hello world")
365+
self.assertEqual(h.hexdigest(), "a5364f7a52ebe2e25f1838a4ca715a893b6fd7a23f2a0d9e9762120da8b1bf53")
366+
357367
def check(self, name, data, hexdigest, shake=False, **kwargs):
358368
length = len(hexdigest)//2
359369
hexdigest = hexdigest.lower()

Lib/test/test_typing.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4892,6 +4892,18 @@ class NontotalMovie(TypedDict, total=False):
48924892
title: Required[str]
48934893
year: int
48944894

4895+
class ParentNontotalMovie(TypedDict, total=False):
4896+
title: Required[str]
4897+
4898+
class ChildTotalMovie(ParentNontotalMovie):
4899+
year: NotRequired[int]
4900+
4901+
class ParentDeeplyAnnotatedMovie(TypedDict):
4902+
title: Annotated[Annotated[Required[str], "foobar"], "another level"]
4903+
4904+
class ChildDeeplyAnnotatedMovie(ParentDeeplyAnnotatedMovie):
4905+
year: NotRequired[Annotated[int, 2000]]
4906+
48954907
class AnnotatedMovie(TypedDict):
48964908
title: Annotated[Required[str], "foobar"]
48974909
year: NotRequired[Annotated[int, 2000]]
@@ -5221,6 +5233,17 @@ def test_get_type_hints_typeddict(self):
52215233
'a': Annotated[Required[int], "a", "b", "c"]
52225234
})
52235235

5236+
self.assertEqual(get_type_hints(ChildTotalMovie), {"title": str, "year": int})
5237+
self.assertEqual(get_type_hints(ChildTotalMovie, include_extras=True), {
5238+
"title": Required[str], "year": NotRequired[int]
5239+
})
5240+
5241+
self.assertEqual(get_type_hints(ChildDeeplyAnnotatedMovie), {"title": str, "year": int})
5242+
self.assertEqual(get_type_hints(ChildDeeplyAnnotatedMovie, include_extras=True), {
5243+
"title": Annotated[Required[str], "foobar", "another level"],
5244+
"year": NotRequired[Annotated[int, 2000]]
5245+
})
5246+
52245247
def test_get_type_hints_collections_abc_callable(self):
52255248
# https://github.com/python/cpython/issues/91621
52265249
P = ParamSpec('P')
@@ -6381,6 +6404,16 @@ def test_required_notrequired_keys(self):
63816404
self.assertEqual(WeirdlyQuotedMovie.__optional_keys__,
63826405
frozenset({"year"}))
63836406

6407+
self.assertEqual(ChildTotalMovie.__required_keys__,
6408+
frozenset({"title"}))
6409+
self.assertEqual(ChildTotalMovie.__optional_keys__,
6410+
frozenset({"year"}))
6411+
6412+
self.assertEqual(ChildDeeplyAnnotatedMovie.__required_keys__,
6413+
frozenset({"title"}))
6414+
self.assertEqual(ChildDeeplyAnnotatedMovie.__optional_keys__,
6415+
frozenset({"year"}))
6416+
63846417
def test_multiple_inheritance(self):
63856418
class One(TypedDict):
63866419
one: int

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,7 @@ MODULE__HASHLIB_DEPS=$(srcdir)/Modules/hashlib.h
26122612
MODULE__IO_DEPS=$(srcdir)/Modules/_io/_iomodule.h
26132613
MODULE__MD5_DEPS=$(srcdir)/Modules/hashlib.h
26142614
MODULE__SHA1_DEPS=$(srcdir)/Modules/hashlib.h
2615-
MODULE__SHA256_DEPS=$(srcdir)/Modules/hashlib.h
2615+
MODULE__SHA256_DEPS=$(srcdir)/Modules/hashlib.h $(srcdir)/Modules/_hacl/include/krml/FStar_UInt_8_16_32_64.h $(srcdir)/Modules/_hacl/include/krml/lowstar_endianness.h $(srcdir)/Modules/_hacl/include/krml/internal/target.h $(srcdir)/Modules/_hacl/Hacl_Streaming_SHA2.h
26162616
MODULE__SHA3_DEPS=$(srcdir)/Modules/_sha3/sha3.c $(srcdir)/Modules/_sha3/sha3.h $(srcdir)/Modules/hashlib.h
26172617
MODULE__SHA512_DEPS=$(srcdir)/Modules/hashlib.h
26182618
MODULE__SOCKET_DEPS=$(srcdir)/Modules/socketmodule.h $(srcdir)/Modules/addrinfo.h $(srcdir)/Modules/getaddrinfo.c $(srcdir)/Modules/getnameinfo.c

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,7 @@ Jean-François Piéronne
14141414
Oleg Plakhotnyuk
14151415
Anatoliy Platonov
14161416
Marcel Plch
1417+
Kirill Podoprigora
14171418
Remi Pointel
14181419
Jon Poler
14191420
Ariel Poliak
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`~unicodedata.is_normalized` to properly handle the UCD 3.2.0
2+
cases. Patch by Dong-hee Na.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The GILState API is now partially compatible with subinterpreters.
2+
Previously, ``PyThreadState_GET()`` and ``PyGILState_GetThisThreadState()``
3+
would get out of sync, causing inconsistent behavior and crashes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the ``defs`` and ``kwdefs`` arguments to :c:func:`PyEval_EvalCodeEx`
2+
and a reference leak in that function.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Enum] - fix psuedo-flag creation
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Replace the builtin :mod:`hashlib` implementations of SHA2-224 and SHA2-256
2+
originally from LibTomCrypt with formally verified, side-channel resistant
3+
code from the `HACL* <https://github.com/hacl-star/hacl-star/>`_ project. The
4+
builtins remain a fallback only used when OpenSSL does not provide them.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure the install path in the registry is only used when the standard
2+
library hasn't been located in any other way.

Modules/Setup.stdlib.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
# hashing builtins, can be disabled with --without-builtin-hashlib-hashes
8080
@MODULE__MD5_TRUE@_md5 md5module.c
8181
@MODULE__SHA1_TRUE@_sha1 sha1module.c
82-
@MODULE__SHA256_TRUE@_sha256 sha256module.c
82+
@MODULE__SHA256_TRUE@_sha256 sha256module.c _hacl/Hacl_Streaming_SHA2.c
8383
@MODULE__SHA512_TRUE@_sha512 sha512module.c
8484
@MODULE__SHA3_TRUE@_sha3 _sha3/sha3module.c
8585
@MODULE__BLAKE2_TRUE@_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c

0 commit comments

Comments
 (0)