Skip to content

Commit 43565a4

Browse files
Merge branch 'main' into manjusaka/build-string
2 parents 0857852 + cc05e4b commit 43565a4

28 files changed

+267
-161
lines changed

Doc/c-api/arg.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,19 @@ small to receive the value.
274274
Convert a Python integer to a C :c:expr:`unsigned long` without
275275
overflow checking.
276276

277+
.. versionchanged:: next
278+
Use :meth:`~object.__index__` if available.
279+
277280
``L`` (:class:`int`) [long long]
278281
Convert a Python integer to a C :c:expr:`long long`.
279282

280283
``K`` (:class:`int`) [unsigned long long]
281284
Convert a Python integer to a C :c:expr:`unsigned long long`
282285
without overflow checking.
283286

287+
.. versionchanged:: next
288+
Use :meth:`~object.__index__` if available.
289+
284290
``n`` (:class:`int`) [:c:type:`Py_ssize_t`]
285291
Convert a Python integer to a C :c:type:`Py_ssize_t`.
286292

Doc/library/socket.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ Constants
476476
network interface instead of its name.
477477

478478
.. versionchanged:: 3.14
479-
Added missing ``IP_RECVERR``, ``IPV6_RECVERR``, ``IP_RECVTTL``, and
480-
``IP_RECVORIGDSTADDR`` on Linux.
479+
Added missing ``IP_FREEBIND``, ``IP_RECVERR``, ``IPV6_RECVERR``,
480+
``IP_RECVTTL``, and ``IP_RECVORIGDSTADDR`` on Linux.
481481

482482
.. versionchanged:: 3.14
483483
Added support for ``TCP_QUICKACK`` on Windows platforms when available.

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,11 @@ New features
20732073
Adding ``?`` after any format unit makes ``None`` be accepted as a value.
20742074
(Contributed by Serhiy Storchaka in :gh:`112068`.)
20752075

2076+
* The ``k`` and ``K`` formats in :c:func:`PyArg_ParseTuple` and
2077+
similar functions now use :meth:`~object.__index__` if available,
2078+
like all other integer formats.
2079+
(Contributed by Serhiy Storchaka in :gh:`112068`.)
2080+
20762081
* Add macros :c:func:`Py_PACK_VERSION` and :c:func:`Py_PACK_FULL_VERSION` for
20772082
bit-packing Python version numbers.
20782083
(Contributed by Petr Viktorin in :gh:`128629`.)

Lib/pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ def do_quit(self, arg):
18341834
reply = 'y'
18351835
self.message('')
18361836
if reply == 'y' or reply == '':
1837-
sys.exit(0)
1837+
sys.exit(1)
18381838
elif reply.lower() == 'n':
18391839
return
18401840

Lib/test/clinic.test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ test_unsigned_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t
14101410
if (nargs < 3) {
14111411
goto skip_optional;
14121412
}
1413-
if (!PyLong_Check(args[2])) {
1413+
if (!PyIndex_Check(args[2])) {
14141414
_PyArg_BadArgument("test_unsigned_long_converter", "argument 3", "int", args[2]);
14151415
goto exit;
14161416
}
@@ -1425,7 +1425,7 @@ test_unsigned_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t
14251425
static PyObject *
14261426
test_unsigned_long_converter_impl(PyObject *module, unsigned long a,
14271427
unsigned long b, unsigned long c)
1428-
/*[clinic end generated code: output=540bb0ba2894e1fe input=f450d94cae1ef73b]*/
1428+
/*[clinic end generated code: output=d74eed227d77a31b input=f450d94cae1ef73b]*/
14291429

14301430

14311431
/*[clinic input]
@@ -1525,7 +1525,7 @@ test_unsigned_long_long_converter(PyObject *module, PyObject *const *args, Py_ss
15251525
if (nargs < 3) {
15261526
goto skip_optional;
15271527
}
1528-
if (!PyLong_Check(args[2])) {
1528+
if (!PyIndex_Check(args[2])) {
15291529
_PyArg_BadArgument("test_unsigned_long_long_converter", "argument 3", "int", args[2]);
15301530
goto exit;
15311531
}
@@ -1542,7 +1542,7 @@ test_unsigned_long_long_converter_impl(PyObject *module,
15421542
unsigned long long a,
15431543
unsigned long long b,
15441544
unsigned long long c)
1545-
/*[clinic end generated code: output=3d69994f618b46bb input=a15115dc41866ff4]*/
1545+
/*[clinic end generated code: output=5ca4e4dfb3db644b input=a15115dc41866ff4]*/
15461546

15471547

15481548
/*[clinic input]

Lib/test/test_asyncio/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from asyncio import base_events
2929
from asyncio import events
3030
from asyncio import format_helpers
31-
from asyncio import futures
3231
from asyncio import tasks
3332
from asyncio.log import logger
3433
from test import support
@@ -104,7 +103,7 @@ def run_until(loop, pred, timeout=support.SHORT_TIMEOUT):
104103
loop.run_until_complete(tasks.sleep(delay))
105104
delay = max(delay * 2, 1.0)
106105
else:
107-
raise futures.TimeoutError()
106+
raise TimeoutError()
108107

109108

110109
def run_once(loop):

Lib/test/test_capi/test_getargs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ def test_I(self):
267267
def test_k(self):
268268
from _testcapi import getargs_k
269269
# k returns 'unsigned long', no range checking
270-
# it does not accept float, or instances with __int__
271270
self.assertRaises(TypeError, getargs_k, 3.14)
272-
self.assertRaises(TypeError, getargs_k, Index())
271+
self.assertEqual(99, getargs_k(Index()))
273272
self.assertEqual(0, getargs_k(IndexIntSubclass()))
274273
self.assertRaises(TypeError, getargs_k, BadIndex())
275-
self.assertRaises(TypeError, getargs_k, BadIndex2())
274+
with self.assertWarns(DeprecationWarning):
275+
self.assertEqual(1, getargs_k(BadIndex2()))
276276
self.assertEqual(0, getargs_k(BadIndex3()))
277277
self.assertRaises(TypeError, getargs_k, Int())
278278
self.assertEqual(0, getargs_k(IntSubclass()))
@@ -419,10 +419,11 @@ def test_K(self):
419419
from _testcapi import getargs_K
420420
# K return 'unsigned long long', no range checking
421421
self.assertRaises(TypeError, getargs_K, 3.14)
422-
self.assertRaises(TypeError, getargs_K, Index())
422+
self.assertEqual(99, getargs_K(Index()))
423423
self.assertEqual(0, getargs_K(IndexIntSubclass()))
424424
self.assertRaises(TypeError, getargs_K, BadIndex())
425-
self.assertRaises(TypeError, getargs_K, BadIndex2())
425+
with self.assertWarns(DeprecationWarning):
426+
self.assertEqual(1, getargs_K(BadIndex2()))
426427
self.assertEqual(0, getargs_K(BadIndex3()))
427428
self.assertRaises(TypeError, getargs_K, Int())
428429
self.assertEqual(0, getargs_K(IntSubclass()))
@@ -432,6 +433,7 @@ def test_K(self):
432433

433434
self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
434435
self.assertEqual(0, getargs_K(0))
436+
self.assertEqual(ULLONG_MAX, getargs_K(ULLONG_MAX))
435437
self.assertEqual(0, getargs_K(ULLONG_MAX+1))
436438

437439
self.assertEqual(42, getargs_K(42))

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,23 @@ def testfunc(n):
19231923
self.assertNotIn("_GUARD_TOS_INT", uops)
19241924
self.assertIn("_CALL_LEN", uops)
19251925

1926+
def test_binary_op_subscr_tuple_int(self):
1927+
def testfunc(n):
1928+
x = 0
1929+
for _ in range(n):
1930+
y = (1, 2)
1931+
if y[0] == 1: # _COMPARE_OP_INT + _GUARD_IS_TRUE_POP are removed
1932+
x += 1
1933+
return x
1934+
1935+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1936+
self.assertEqual(res, TIER2_THRESHOLD)
1937+
self.assertIsNotNone(ex)
1938+
uops = get_opnames(ex)
1939+
self.assertIn("_BINARY_OP_SUBSCR_TUPLE_INT", uops)
1940+
self.assertNotIn("_COMPARE_OP_INT", uops)
1941+
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
1942+
19261943

19271944
def global_identity(x):
19281945
return x

Lib/test/test_hashlib.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ def get_fips_mode():
6262

6363
requires_blake2 = unittest.skipUnless(_blake2, 'requires _blake2')
6464

65-
# bpo-46913: Don't test the _sha3 extension on a Python UBSAN build
66-
# TODO(gh-99108): Revisit this after _sha3 uses HACL*.
67-
SKIP_SHA3 = support.check_sanitizer(ub=True)
68-
requires_sha3 = unittest.skipUnless(not SKIP_SHA3, 'requires _sha3')
65+
try:
66+
import _sha3
67+
except ImportError:
68+
_sha3 = None
69+
70+
requires_sha3 = unittest.skipUnless(_sha3, 'requires _sha3')
6971

7072

7173
def hexstr(s):
@@ -132,8 +134,6 @@ def __init__(self, *args, **kwargs):
132134

133135
self.constructors_to_test = {}
134136
for algorithm in algorithms:
135-
if SKIP_SHA3 and algorithm.startswith('sha3_'):
136-
continue
137137
self.constructors_to_test[algorithm] = set()
138138

139139
# For each algorithm, test the direct constructor and the use
@@ -180,20 +180,18 @@ def add_builtin_constructor(name):
180180
add_builtin_constructor('sha256')
181181
add_builtin_constructor('sha384')
182182
add_builtin_constructor('sha512')
183+
_sha3 = self._conditional_import_module('_sha3')
184+
if _sha3:
185+
add_builtin_constructor('sha3_224')
186+
add_builtin_constructor('sha3_256')
187+
add_builtin_constructor('sha3_384')
188+
add_builtin_constructor('sha3_512')
189+
add_builtin_constructor('shake_128')
190+
add_builtin_constructor('shake_256')
183191
if _blake2:
184192
add_builtin_constructor('blake2s')
185193
add_builtin_constructor('blake2b')
186194

187-
if not SKIP_SHA3:
188-
_sha3 = self._conditional_import_module('_sha3')
189-
if _sha3:
190-
add_builtin_constructor('sha3_224')
191-
add_builtin_constructor('sha3_256')
192-
add_builtin_constructor('sha3_384')
193-
add_builtin_constructor('sha3_512')
194-
add_builtin_constructor('shake_128')
195-
add_builtin_constructor('shake_256')
196-
197195
super(HashLibTestCase, self).__init__(*args, **kwargs)
198196

199197
@property

Lib/test/test_hmac.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,6 @@ def exc_type(self):
980980
return _hashlib.UnsupportedDigestmodError
981981

982982
def test_hmac_digest_digestmod_parameter(self):
983-
# TODO(picnixz): remove default arguments in _hashlib.hmac_digest()
984-
# since the return value is not a HMAC object but a bytes object.
985983
for value in [object, 'unknown', 1234, None]:
986984
with (
987985
self.subTest(value=value),

0 commit comments

Comments
 (0)