8000 Merge branch 'master' of https://github.com/terryjreedy/cpython into … · python/cpython@6ad67ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ad67ba

Browse files
committed
Merge branch 'master' of https://github.com/terryjreedy/cpython into print-speed
2 parents eebd004 + b798ab0 commit 6ad67ba

21 files changed

+203
-46
lines changed

Doc/c-api/arg.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ which disallows mutable objects such as :class:`bytearray`.
149149
Previously, :exc:`TypeError` was raised when embedded null code points
150150
were encountered in the Python string.
151151

152-
.. deprecated-removed:: 3.3 4.0
152+
.. deprecated-removed:: 3.3 3.12
153153
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
154154
:c:func:`PyUnicode_AsWideCharString`.
155155

@@ -158,23 +158,23 @@ which disallows mutable objects such as :class:`bytearray`.
158158
Unicode data buffer, the second one its length. This variant allows
159159
null code points.
160160

161-
.. deprecated-removed:: 3.3 4.0
161+
.. deprecated-removed:: 3.3 3.12
162162
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
163163
:c:func:`PyUnicode_AsWideCharString`.
164164

165165
``Z`` (:class:`str` or ``None``) [const Py_UNICODE \*]
166166
Like ``u``, but the Python object may also be ``None``, in which case the
167167
:c:type:`Py_UNICODE` pointer is set to ``NULL``.
168168

169-
.. deprecated-removed:: 3.3 4.0
169+
.. deprecated-removed:: 3.3 3.12
170170
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
171171
:c:func:`PyUnicode_AsWideCharString`.
172172

173173
``Z#`` (:class:`str` or ``None``) [const Py_UNICODE \*, :c:type:`Py_ssize_t`]
174174
Like ``u#``, but the Python object may also be ``None``, in which case the
175175
:c:type:`Py_UNICODE` pointer is set to ``NULL``.
176176

177-
.. deprecated-removed:: 3.3 4.0
177+
.. deprecated-removed:: 3.3 3.12
178178
Part of the old-style :c:type:`Py_UNICODE` API; please migrate to using
179179
:c:func:`PyUnicode_AsWideCharString`.
180180

Doc/c-api/unicode.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ points must be below 1114112 (which is the full Unicode range).
1919

2020
:c:type:`Py_UNICODE*` and UTF-8 representations are created on demand and cached
2121
in the Unicode object. The :c:type:`Py_UNICODE*` representation is deprecated
22-
and inefficient; it should be avoided in performance- or memory-sensitive
23-
situations.
22+
and inefficient.
2423

2524
Due to the transition between the old APIs and the new APIs, Unicode objects
2625
can internally be in two states depending on how they were created:
@@ -434,7 +433,7 @@ APIs:
434433
435434
If *u* is ``NULL``, this function behaves like :c:func:`PyUnicode_FromUnicode`
436435
with the buffer set to ``NULL``. This usage is deprecated in favor of
437-
:c:func:`PyUnicode_New`.
436+
:c:func:`PyUnicode_New`, and will be removed in Python 3.12.
438437
439438
440439
.. c:function:: PyObject *PyUnicode_FromString(const char *u)
@@ -676,7 +675,7 @@ APIs:
676675
Deprecated Py_UNICODE APIs
677676
""""""""""""""""""""""""""
678677
679-
.. deprecated-removed:: 3.3 4.0
678+
.. deprecated-removed:: 3.3 3.12
680679
681680
These API functions are deprecated with the implementation of :pep:`393`.
682681
Extension modules can continue using them, as they will not be removed in Python

Doc/library/unittest.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ Test modules and packages can customize test loading and discovery by through
330330
the `load_tests protocol`_.
331331

332332
.. versionchanged:: 3.4
333-
Test discovery supports :term:`namespace packages <namespace package>`.
333+
Test discovery supports :term:`namespace packages <namespace package>`
334+
for start directory. Note that you need to the top level directory too.
335+
(e.g. ``python -m unittest discover -s root/namespace -t root``).
334336

335337

336338
.. _organizing-tests:
@@ -1870,11 +1872,15 @@ Loading and running tests
18701872

18711873
.. versionchanged:: 3.4
18721874
Modules that raise :exc:`SkipTest` on import are recorded as skips,
1873-
not errors.
1874-
Discovery works for :term:`namespace packages <namespace package>`.
1875-
Paths are sorted before being imported so that execution order is
1876-
the same even if the underlying file system's ordering is not
1877-
dependent on file name.
1875+
not errors.
1876+
1877+
.. versionchanged:: 3.4
1878+
*start_dir* can be a :term:`namespace packages <namespace package>`.
1879+
1880+
.. versionchanged:: 3.4
1881+
Paths are sorted before being imported so that execution order is the
1882+
same even if the underlying file system's ordering is not dependent
1883+
on file name.
18781884

18791885
.. versionchanged:: 3.5
18801886
Found packages are now checked for ``load_tests`` regardless of

Include/methodobject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ struct PyMethodDef {
4141
};
4242
typedef struct PyMethodDef PyMethodDef;
4343

44+
/* PyCFunction_New is declared as a function for stable ABI (declaration is
45+
* needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro
46+
* that calls PyCFunction_NewEx. */
47+
PyAPI_FUNC(PyObject *) PyCFunction_New(PyMethodDef *, PyObject *);
4448
#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
49+
50+
/* PyCFunction_NewEx is similar: on 3.9+, this calls PyCMethod_New. */
4551
PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
4652
PyObject *);
4753

Lib/test/test_getargs2.py

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
from test import support
66
from test.support import import_helper
7+
from test.support import warnings_helper
78
# Skip this test if the _testcapi module isn't available.
89
_testcapi = import_helper.import_module('_testcapi')
910
from _testcapi import getargs_keywords, getargs_keyword_only
@@ -979,42 +980,66 @@ def test_et_hash(self):
979980
@support.requires_legacy_unicode_capi
980981
def test_u(self):
981982
from _testcapi import getargs_u
982-
self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
983-
self.assertRaises(ValueError, getargs_u, 'nul:\0')
984-
self.assertRaises(TypeError, getargs_u, b'bytes')
985-
self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
986-
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
987-
self.assertRaises(TypeError, getargs_u, None)
983+
with self.assertWarns(DeprecationWarning):
984+
self.assertEqual(getargs_u('abc\xe9'), 'abc\xe9')
985+
with self.assertWarns(DeprecationWarning):
986+
self.assertRaises(ValueError, getargs_u, 'nul:\0')
987+
with self.assertWarns(DeprecationWarning):
988+
self.assertRaises(TypeError, getargs_u, b'bytes')
989+
with self.assertWarns(DeprecationWarning):
990+
self.assertRaises(TypeError, getargs_u, bytearray(b'bytearray'))
991+
with self.assertWarns(DeprecationWarning):
992+
self.assertRaises(TypeError, getargs_u, memoryview(b'memoryview'))
993+
with self.assertWarns(DeprecationWarning):
994+
self.assertRaises(TypeError, getargs_u, None)
988995

989996
@support.requires_legacy_unicode_capi
990997
def test_u_hash(self):
991998
from _testcapi import getargs_u_hash
992-
self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
993-
self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
994-
self.assertRaises(TypeError, getargs_u_hash, b'bytes')
995-
self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
996-
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
997-
self.assertRaises(TypeError, getargs_u_hash, None)
999+
with self.assertWarns(DeprecationWarning):
1000+
self.assertEqual(getargs_u_hash('abc\xe9'), 'abc\xe9')
1001+
with self.assertWarns(DeprecationWarning):
1002+
self.assertEqual(getargs_u_hash('nul:\0'), 'nul:\0')
1003+
with self.assertWarns(DeprecationWarning):
1004+
self.assertRaises(TypeError, getargs_u_hash, b'bytes')
1005+
with self.assertWarns(DeprecationWarning):
1006+
self.assertRaises(TypeError, getargs_u_hash, bytearray(b'bytearray'))
1007+
with self.assertWarns(DeprecationWarning):
1008+
self.assertRaises(TypeError, getargs_u_hash, memoryview(b'memoryview'))
1009+
with self.assertWarns(DeprecationWarning):
1010+
self.assertRaises(TypeError, getargs_u_hash, None)
9981011

9991012
@support.requires_legacy_unicode_capi
10001013
def test_Z(self):
10011014
from _testcapi import getargs_Z
1002-
self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
1003-
self.assertRaises(ValueError, getargs_Z, 'nul:\0')
1004-
self.assertRaises(TypeError, getargs_Z, b'bytes')
1005-
self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
1006-
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
1007-
self.assertIsNone(getargs_Z(None))
1015+
with self.assertWarns(DeprecationWarning):
1016+
self.assertEqual(getargs_Z('abc\xe9'), 'abc\xe9')
1017+
with self.assertWarns(DeprecationWarning):
1018+
self.assertRaises(ValueError, getargs_Z, 'nul:\0')
1019+
with self.assertWarns(DeprecationWarning):
1020+
self.assertRaises(TypeError, getargs_Z, b'bytes')
1021+
with self.assertWarns(DeprecationWarning):
1022+
self.assertRaises(TypeError, getargs_Z, bytearray(b'bytearray'))
1023+
with self.assertWarns(DeprecationWarning):
1024+
self.assertRaises(TypeError, getargs_Z, memoryview(b'memoryview'))
1025+
with self.assertWarns(DeprecationWarning):
1026+
self.assertIsNone(getargs_Z(None))
10081027

10091028
@support.requires_legacy_unicode_capi
10101029
def test_Z_hash(self):
10111030
from _testcapi import getargs_Z_hash
1012-
self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
1013-
self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
1014-
self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
1015-
self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
1016-
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
1017-
self.assertIsNone(getargs_Z_hash(None))
1031+
with self.assertWarns(DeprecationWarning):
1032+
self.assertEqual(getargs_Z_hash('abc\xe9'), 'abc\xe9')
1033+
with self.assertWarns(DeprecationWarning):
1034+
self.assertEqual(getargs_Z_hash('nul:\0'), 'nul:\0')
1035+
with self.assertWarns(DeprecationWarning):
1036+
self.assertRaises(TypeError, getargs_Z_hash, b'bytes')
1037+
with self.assertWarns(DeprecationWarning):
1038+
self.assertRaises(TypeError, getargs_Z_hash, bytearray(b'bytearray'))
1039+
with self.assertWarns(DeprecationWarning):
1040+
self.assertRaises(TypeError, getargs_Z_hash, memoryview(b'memoryview'))
1041+
with self.assertWarns(DeprecationWarning):
1042+
self.assertIsNone(getargs_Z_hash(None))
10181043

10191044

10201045
class Object_TestCase(unittest.TestCase):
@@ -1053,6 +1078,8 @@ def test(self):
10531078

10541079
class SkipitemTest(unittest.TestCase):
10551080

1081+
# u, and Z raises DeprecationWarning
1082+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
10561083
def test_skipitem(self):
10571084
"""
10581085
If this test failed, you probably added a new "format unit"
@@ -1221,6 +1248,14 @@ class Test_testcapi(unittest.TestCase):
12211248
for name in dir(_testcapi)
12221249
if name.startswith('test_') and name.endswith('_code'))
12231250

1251+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
1252+
def test_u_code(self):
1253+
_testcapi.test_u_code()
1254+
1255+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
1256+
def test_Z_code(self):
1257+
_testcapi.test_Z_code()
1258+
12241259

12251260
if __name__ == "__main__":
12261261
unittest.main()

Lib/test/test_importlib/fixtures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import tempfile
66
import textwrap
77
import contextlib
8+
import unittest
89

910
from test.support.os_helper import FS_NONASCII
1011
from typing import Dict, Union
@@ -220,6 +221,7 @@ def setUp(self):
220221
build_files(self.files)
221222

222223

224+
223225
def build_files(file_defs, prefix=pathlib.Path()):
224226
"""Build a set of files/directories, as described by the
225227
@@ -258,6 +260,9 @@ class FileBuilder:
258260
def unicode_filename(self):
259261
return FS_NONASCII or self.skip("File system does not support non-ascii.")
260262

263+
def skip(self, reason):
264+
raise unittest.SkipTest(reason)
265+
261266

262267
def DALS(str):
263268
"Dedent and left-strip"

Lib/test/test_io.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3767,6 +3767,33 @@ def test_del__CHUNK_SIZE_SystemError(self):
37673767
with self.assertRaises(AttributeError):
37683768
del t._CHUNK_SIZE
37693769

3770+
def test_internal_buffer_size(self):
3771+
# bpo-43260: TextIOWrapper's internal buffer should not store
3772+
# data larger than chunk size.
3773+
chunk_size = 8192 # default chunk size, updated later
3774+
3775+
class MockIO(self.MockRawIO):
3776+
def write(self, data):
3777+
if len(data) > chunk_size:
3778+
raise RuntimeError
3779+
return super().write(data)
3780+
3781+
buf = MockIO()
3782+
t = self.TextIOWrapper(buf, encoding="ascii")
3783+
chunk_size = t._CHUNK_SIZE
3784+
t.write("abc")
3785+
t.write("def")
3786+
# default chunk size is 8192 bytes so t don't write data to buf.
3787+
self.assertEqual([], buf._write_stack)
3788+
3789+
with self.assertRaises(RuntimeError):
3790+
t.write("x"*(chunk_size+1))
3791+
3792+
self.assertEqual([b"abcdef"], buf._write_stack)
3793+
t.write("ghi")
3794+
t.write("x"*chunk_size)
3795+
self.assertEqual([b"abcdef", b"ghi", b"x"*chunk_size], buf._write_stack)
3796+
37703797

37713798
class PyTextIOWrapperTest(TextIOWrapperTest):
37723799
io = pyio

Lib/test/test_traceback.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,29 @@ def test_format_exception_only_exc(self):
232232
output = traceback.format_exception_only(Exception("projector"))
233233
self.assertEqual(output, ["Exception: projector\n"])
234234

235+
def test_exception_is_None(self):
236+
NONE_EXC_STRING = 'NoneType: None\n'
237+
excfile = StringIO()
238+
traceback.print_exception(None, file=excfile)
239+
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
240+
241+
excfile = StringIO()
242+
traceback.print_exception(None, None, None, file=excfile)
243+
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
244+
245+
excfile = StringIO()
246+
traceback.print_exc(None, file=excfile)
247+
self.assertEqual(excfile.getvalue(), NONE_EXC_STRING)
248+
249+
self.assertEqual(traceback.format_exc(None), NONE_EXC_STRING)
250+
self.assertEqual(traceback.format_exception(None), [NONE_EXC_STRING])
251+
self.assertEqual(
252+
traceback.format_exception(None, None, None), [NONE_EXC_STRING])
253+
self.assertEqual(
254+
traceback.format_exception_only(None), [NONE_EXC_STRING])
255+
self.assertEqual(
256+
traceback.format_exception_only(None, None), [NONE_EXC_STRING])
257+
235258

236259
class TracebackFormatTests(unittest.TestCase):
237260

Lib/test/test_unicode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,12 +2368,14 @@ def test_resize(self):
23682368
text = 'a' * length + 'b'
23692369

23702370
# fill wstr internal field
2371-
abc = getargs_u(text)
2371+
with self.assertWarns(DeprecationWarning):
2372+
abc = getargs_u(text)
23722373
self.assertEqual(abc, text)
23732374

23742375
# resize text: wstr field must be cleared and then recomputed
23752376
text += 'c'
2376-
abcdef = getargs_u(text)
2377+
with self.assertWarns(DeprecationWarning):
2378+
abcdef = getargs_u(text)
23772379
self.assertNotEqual(abc, abcdef)
23782380
self.assertEqual(abcdef, text)
23792381

Lib/traceback.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def _parse_value_tb(exc, value, tb):
9191
if (value is _sentinel) != (tb is _sentinel):
9292
raise ValueError("Both or neither of value and tb must be given")
9393
if value is tb is _sentinel:
94-
return exc, exc.__traceback__
94+
if exc is not None:
95+
return exc, exc.__traceback__
96+
else:
97+
return None, None
9598
return value, tb
9699

97100

@@ -528,7 +531,9 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
528531
cause = None
529532

530533
if compact:
531-
need_context = cause is None and not e.__suppress_context__
534+
need_context = (cause is None and
535+
e is not None and
536+
not e.__suppress_context__)
532537
else:
533538
need_context = True
534539
if (e and e.__context__ is not None
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :c:func:`PyCFunction_New` function is now exported in the ABI when
2+
compiled with ``-fvisibility=hidden``.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Simple calls to ``type(object)`` are now faster due to the
2+
``vectorcall`` calling convention. Patch by Dennis Sweeney.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``PyArg_Parse*()`` functions now emits ``DeprecationWarning`` when ``u`` or
2+
``Z`` format is used. See :pep:`623` for detail.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update some deprecated unicode APIs which are documented as "will be removed
2+
in 4.0" to "3.12". See :pep:`623` for detail.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix recent regression in None argument handling in :mod:`~traceback` module functions.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix TextIOWrapper can not flush internal buffer forever after very large
2+
text is written.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle None in single-arg versions of :func:`~traceback.print_exception` and :func:`~traceback.format_exception`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix test_importlib to correctly skip Unicode file tests if the fileystem
2+
does not support them.

0 commit comments

Comments
 (0)
0