Skip to content

Commit 3ebdd97

Browse files
authored
Merge branch 'main' into pep750-concat-update
2 parents c9ed06b + 35e2c35 commit 3ebdd97

File tree

15 files changed

+345
-401
lines changed

15 files changed

+345
-401
lines changed

Doc/c-api/exceptions.rst

Lines changed: 187 additions & 251 deletions
Large diffs are not rendered by default.

Doc/conf.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -233,75 +233,6 @@
233233
# Temporary undocumented names.
234234
# In future this list must be empty.
235235
nitpick_ignore += [
236-
# C API: Standard Python exception classes
237-
('c:data', 'PyExc_ArithmeticError'),
238-
('c:data', 'PyExc_AssertionError'),
239-
('c:data', 'PyExc_AttributeError'),
240-
('c:data', 'PyExc_BaseException'),
241-
('c:data', 'PyExc_BaseExceptionGroup'),
242-
('c:data', 'PyExc_BlockingIOError'),
243-
('c:data', 'PyExc_BrokenPipeError'),
244-
('c:data', 'PyExc_BufferError'),
245-
('c:data', 'PyExc_ChildProcessError'),
246-
('c:data', 'PyExc_ConnectionAbortedError'),
247-
('c:data', 'PyExc_ConnectionError'),
248-
('c:data', 'PyExc_ConnectionRefusedError'),
249-
('c:data', 'PyExc_ConnectionResetError'),
250-
('c:data', 'PyExc_EOFError'),
251-
('c:data', 'PyExc_Exception'),
252-
('c:data', 'PyExc_FileExistsError'),
253-
('c:data', 'PyExc_FileNotFoundError'),
254-
('c:data', 'PyExc_FloatingPointError'),
255-
('c:data', 'PyExc_GeneratorExit'),
256-
('c:data', 'PyExc_ImportError'),
257-
('c:data', 'PyExc_IndentationError'),
258-
('c:data', 'PyExc_IndexError'),
259-
('c:data', 'PyExc_InterruptedError'),
260-
('c:data', 'PyExc_IsADirectoryError'),
261-
('c:data', 'PyExc_KeyboardInterrupt'),
262-
('c:data', 'PyExc_KeyError'),
263-
('c:data', 'PyExc_LookupError'),
264-
('c:data', 'PyExc_MemoryError'),
265-
('c:data', 'PyExc_ModuleNotFoundError'),
266-
('c:data', 'PyExc_NameError'),
267-
('c:data', 'PyExc_NotADirectoryError'),
268-
('c:data', 'PyExc_NotImplementedError'),
269-
('c:data', 'PyExc_OSError'),
270-
('c:data', 'PyExc_OverflowError'),
271-
('c:data', 'PyExc_PermissionError'),
272-
('c:data', 'PyExc_ProcessLookupError'),
273-
('c:data', 'PyExc_PythonFinalizationError'),
274-
('c:data', 'PyExc_RecursionError'),
275-
('c:data', 'PyExc_ReferenceError'),
276-
('c:data', 'PyExc_RuntimeError'),
277-
('c:data', 'PyExc_StopAsyncIteration'),
278-
('c:data', 'PyExc_StopIteration'),
279-
('c:data', 'PyExc_SyntaxError'),
280-
('c:data', 'PyExc_SystemError'),
281-
('c:data', 'PyExc_SystemExit'),
282-
('c:data', 'PyExc_TabError'),
283-
('c:data', 'PyExc_TimeoutError'),
284-
('c:data', 'PyExc_TypeError'),
285-
('c:data', 'PyExc_UnboundLocalError'),
286-
('c:data', 'PyExc_UnicodeDecodeError'),
287-
('c:data', 'PyExc_UnicodeEncodeError'),
288-
('c:data', 'PyExc_UnicodeError'),
289-
('c:data', 'PyExc_UnicodeTranslateError'),
290-
('c:data', 'PyExc_ValueError'),
291-
('c:data', 'PyExc_ZeroDivisionError'),
292-
# C API: Standard Python warning classes
293-
('c:data', 'PyExc_BytesWarning'),
294-
('c:data', 'PyExc_DeprecationWarning'),
295-
('c:data', 'PyExc_EncodingWarning'),
296-
('c:data', 'PyExc_FutureWarning'),
297-
('c:data', 'PyExc_ImportWarning'),
298-
('c:data', 'PyExc_PendingDeprecationWarning'),
299-
('c:data', 'PyExc_ResourceWarning'),
300-
('c:data', 'PyExc_RuntimeWarning'),
301-
('c:data', 'PyExc_SyntaxWarning'),
302-
('c:data', 'PyExc_UnicodeWarning'),
303-
('c:data', 'PyExc_UserWarning'),
304-
('c:data', 'PyExc_Warning'),
305236
# Undocumented public C macros
306237
('c:macro', 'Py_BUILD_ASSERT'),
307238
('c:macro', 'Py_BUILD_ASSERT_EXPR'),

Doc/library/codecs.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ wider range of codecs when working with binary files:
243243
.. function:: iterencode(iterator, encoding, errors='strict', **kwargs)
244244

245245
Uses an incremental encoder to iteratively encode the input provided by
246-
*iterator*. This function is a :term:`generator`.
247-
The *errors* argument (as well as any
246+
*iterator*. *iterator* must yield :class:`str` objects.
247+
This function is a :term:`generator`. The *errors* argument (as well as any
248248
other keyword argument) is passed through to the incremental encoder.
249249

250250
This function requires that the codec accept text :class:`str` objects
@@ -255,8 +255,8 @@ wider range of codecs when working with binary files:
255255
.. function:: iterdecode(iterator, encoding, errors='strict', **kwargs)
256256

257257
Uses an incremental decoder to iteratively decode the input provided by
258-
*iterator*. This function is a :term:`generator`.
259-
The *errors* argument (as well as any
258+
*iterator*. *iterator* must yield :class:`bytes` objects.
259+
This function is a :term:`generator`. The *errors* argument (as well as any
260260
other keyword argument) is passed through to the incremental decoder.
261261

262262
This function requires that the codec accept :class:`bytes` objects

Lib/codecs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def readlines(self, sizehint=None, keepends=True):
618618
method and are included in the list entries.
619619
620620
sizehint, if given, is ignored since there is no efficient
621-
way to finding the true end-of-line.
621+
way of finding the true end-of-line.
622622
623623
"""
624624
data = self.read()
@@ -709,13 +709,13 @@ def read(self, size=-1):
709709

710710
return self.reader.read(size)
711711

712-
def readline(self, size=None):
712+
def readline(self, size=None, keepends=True):
713713

714-
return self.reader.readline(size)
714+
return self.reader.readline(size, keepends)
715715

716-
def readlines(self, sizehint=None):
716+
def readlines(self, sizehint=None, keepends=True):
717717

718-
return self.reader.readlines(sizehint)
718+
return self.reader.readlines(sizehint, keepends)
719719

720720
def __next__(self):
721721

Lib/test/test_builtin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def f(): """doc"""
436436
# test both direct compilation and compilation via AST
437437
codeobjs = []
438438
codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval))
439-
tree = ast.parse(codestr)
439+
tree = ast.parse(codestr, optimize=optval)
440440
codeobjs.append(compile(tree, "<test>", "exec", optimize=optval))
441441
for code in codeobjs:
442442
ns = {}
@@ -624,7 +624,7 @@ def test_compile_ast(self):
624624
for opt in [opt1, opt2]:
625625
opt_right = opt.value.right
626626
self.assertIsInstance(opt_right, ast.Constant)
627-
self.assertEqual(opt_right.value, True)
627+
self.assertEqual(opt_right.value, __debug__)
628628

629629
def test_delattr(self):
630630
sys.spam = 1

Lib/test/test_string/_support.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,45 @@
22

33

44
class TStringBaseCase:
5+
def assertInterpolationEqual(self, i, exp):
6+
"""Test Interpolation equality.
7+
8+
The *i* argument must be an Interpolation instance.
9+
10+
The *exp* argument must be a tuple of the form
11+
(value, expression, conversion, format_spec) where the final three
12+
items may be omitted and are assumed to be '', None and '' respectively.
13+
"""
14+
if len(exp) == 4:
15+
actual = (i.value, i.expression, i.conversion, i.format_spec)
16+
self.assertEqual(actual, exp)
17+
elif len(exp) == 3:
18+
self.assertEqual((i.value, i.expression, i.conversion), exp)
19+
self.assertEqual(i.format_spec, "")
20+
elif len(exp) == 2:
21+
self.assertEqual((i.value, i.expression), exp)
22+
self.assertEqual(i.conversion, None)
23+
self.assertEqual(i.format_spec, "")
24+
elif len(exp) == 1:
25+
self.assertEqual((i.value,), exp)
26+
self.assertEqual(i.expression, "")
27+
self.assertEqual(i.conversion, None)
28+
self.assertEqual(i.format_spec, "")
29+
530
def assertTStringEqual(self, t, strings, interpolations):
631
"""Test template string literal equality.
732
833
The *strings* argument must be a tuple of strings equal to *t.strings*.
934
1035
The *interpolations* argument must be a sequence of tuples which are
11-
compared against *t.interpolations*. Each tuple consists of
12-
(value, expression, conversion, format_spec), though the final two
13-
items may be omitted, and are assumed to be None and '' respectively.
36+
compared against *t.interpolations*. Each tuple must match the form
37+
described in the `assertInterpolationEqual` method.
1438
"""
1539
self.assertEqual(t.strings, strings)
1640
self.assertEqual(len(t.interpolations), len(interpolations))
1741

1842
for i, exp in zip(t.interpolations, interpolations, strict=True):
19-
if len(exp) == 4:
20-
actual = (i.value, i.expression, i.conversion, i.format_spec)
21-
self.assertEqual(actual, exp)
22-
continue
23-
24-
if len(exp) == 3:
25-
self.assertEqual((i.value, i.expression, i.conversion), exp)
26-
self.assertEqual(i.format_spec, '')
27-
continue
28-
29-
self.assertEqual((i.value, i.expression), exp)
30-
self.assertEqual(i.format_spec, '')
31-
self.assertIsNone(i.conversion)
43+
self.assertInterpolationEqual(i, exp)
3244

3345

3446
def convert(value, conversion):

Lib/test/test_string/test_templatelib.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ def test_basic_creation(self):
4545
self.assertEqual(len(t.interpolations), 0)
4646
self.assertEqual(fstring(t), 'Hello,\nworld')
4747

48+
def test_interpolation_creation(self):
49+
i = Interpolation('Maria', 'name', 'a', 'fmt')
50+
self.assertInterpolationEqual(i, ('Maria', 'name', 'a', 'fmt'))
51+
52+
i = Interpolation('Maria', 'name', 'a')
53+
self.assertInterpolationEqual(i, ('Maria', 'name', 'a'))
54+
55+
i = Interpolation('Maria', 'name')
56+
self.assertInterpolationEqual(i, ('Maria', 'name'))
57+
58+
i = Interpolation('Maria')
59+
self.assertInterpolationEqual(i, ('Maria',))
60+
4861
def test_creation_interleaving(self):
4962
# Should add strings on either side
5063
t = Template(Interpolation('Maria', 'name', None, ''))

Lib/test/test_zstd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,8 +2673,12 @@ def test_compress_locking(self):
26732673
input = b'a'* (16*_1K)
26742674
num_threads = 8
26752675

2676+
# gh-136394: the first output of .compress() includes the frame header
2677+
# we run the first .compress() call outside of the threaded portion
2678+
# to make the test order-independent
2679+
26762680
comp = ZstdCompressor()
2677-
parts = []
2681+
parts = [comp.compress(input, ZstdCompressor.FLUSH_BLOCK)]
26782682
for _ in range(num_threads):
26792683
res = comp.compress(input, ZstdCompressor.FLUSH_BLOCK)
26802684
if res:
@@ -2683,7 +2687,7 @@ def test_compress_locking(self):
26832687
expected = b''.join(parts) + rest1
26842688

26852689
comp = ZstdCompressor()
2686-
output = []
2690+
output = [comp.compress(input, ZstdCompressor.FLUSH_BLOCK)]
26872691
def run_method(method, input_data, output_data):
26882692
res = method(input_data, ZstdCompressor.FLUSH_BLOCK)
26892693
if res:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Improve performance of ``PyLongObject`` conversion functions
2+
``PyLong_AsLongAndOverflow()``, ``PyLong_AsSsize_t()``, ``PyLong_AsUnsignedLong()``, ``PyLong_AsSize_t()``,
3+
``PyLong_AsUnsignedLongMask()``, ``PyLong_AsUnsignedLongLongMask()``, ``PyLong_AsLongLongAndOverflow()``
4+
for integers larger than 2**30 up to 30%.
5+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``Interpolation.expression`` now has a default, the empty string.

0 commit comments

Comments
 (0)