Update to Python 3.13.0rc3

This commit is contained in:
Miro Hrončok 2024-10-01 17:36:42 +02:00
commit 7aec56a73f
4 changed files with 7 additions and 157 deletions

View file

@ -1,83 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?=
<10796600+picnixz@users.noreply.github.com>
Date: Wed, 18 Sep 2024 18:42:33 +0200
Subject: [PATCH] 00439: gh-122145: Handle an empty AST body when reporting
tracebacks
(cherry picked from commit 5cd50cb6eb28e525f0c838e049e900ea982a5a23)
---
Lib/test/test_traceback.py | 35 +++++++++++++++++++
Lib/traceback.py | 2 ++
...-07-23-12-38-14.gh-issue-122145.sTO8nX.rst | 3 ++
3 files changed, 40 insertions(+)
create mode 100644 Misc/NEWS.d/next/Library/2024-07-23-12-38-14.gh-issue-122145.sTO8nX.rst
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index 574d5dab97..a78aded4cc 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -3304,6 +3304,41 @@ def format_frame_summary(self, frame_summary, colorize=False):
f' File "{__file__}", line {lno}, in f\n 1/0\n'
)
+ def test_summary_should_show_carets(self):
+ # See: https://github.com/python/cpython/issues/122353
+
+ # statement to execute and to get a ZeroDivisionError for a traceback
+ statement = "abcdef = 1 / 0 and 2.0"
+ colno = statement.index('1 / 0')
+ end_colno = colno + len('1 / 0')
+
+ # Actual line to use when rendering the traceback
+ # and whose AST will be extracted (it will be empty).
+ cached_line = '# this line will be used during rendering'
+ self.addCleanup(unlink, TESTFN)
+ with open(TESTFN, "w") as file:
+ file.write(cached_line)
+ linecache.updatecache(TESTFN, {})
+
+ try:
+ exec(compile(statement, TESTFN, "exec"))
+ except ZeroDivisionError as exc:
+ # This is the simplest way to create a StackSummary
+ # whose FrameSummary items have their column offsets.
+ s = traceback.TracebackException.from_exception(exc).stack
+ self.assertIsInstance(s, traceback.StackSummary)
+ with unittest.mock.patch.object(s, '_should_show_carets',
+ wraps=s._should_show_carets) as ff:
+ self.assertEqual(len(s), 2)
+ self.assertListEqual(
+ s.format_frame_summary(s[1]).splitlines(),
+ [
+ f' File "{TESTFN}", line 1, in <module>',
+ f' {cached_line}'
+ ]
+ )
+ ff.assert_called_with(colno, end_colno, [cached_line], None)
+
class Unrepresentable:
def __repr__(self) -> str:
raise Exception("Unrepresentable")
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 3e708c6f86..0fe7187a0c 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -698,6 +698,8 @@ def _should_show_carets(self, start_offset, end_offset, all_lines, anchors):
with suppress(SyntaxError, ImportError):
import ast
tree = ast.parse('\n'.join(all_lines))
+ if not tree.body:
+ return False
statement = tree.body[0]
value = None
def _spawns_full_line(value):
diff --git a/Misc/NEWS.d/next/Library/2024-07-23-12-38-14.gh-issue-122145.sTO8nX.rst b/Misc/NEWS.d/next/Library/2024-07-23-12-38-14.gh-issue-122145.sTO8nX.rst
new file mode 100644
index 0000000000..a4282f12d9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-23-12-38-14.gh-issue-122145.sTO8nX.rst
@@ -0,0 +1,3 @@
+Fix an issue when reporting tracebacks corresponding to Python code
+emitting an empty AST body.
+Patch by Nikita Sobolev and Bénédikt Tran.

View file

@ -1,62 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: luk1337 <priv.luk@gmail.com>
Date: Thu, 19 Sep 2024 18:05:20 +0200
Subject: [PATCH] 00440: gh-124160: Pass main_tstate to
update_global_state_for_extension()
(cherry picked from commit 7331d0f70bc9fbac177b76b6ec03486430383425)
---
.../C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst | 2 ++
Programs/_testembed.c | 9 +++++++++
Python/import.c | 2 +-
3 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst
diff --git a/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst b/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst
new file mode 100644
index 0000000000..26e7aef08e
--- /dev/null
+++ b/Misc/NEWS.d/next/C_API/2024-09-18-18-40-30.gh-issue-124160.Zy-VKi.rst
@@ -0,0 +1,2 @@
+Fix crash when importing modules containing state and single-phase
+initialization in a subinterpreter.
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index e341f0c6bf..96dbfabd7e 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -94,6 +94,14 @@ static void _testembed_Py_Initialize(void)
}
+static int test_import_in_subinterpreters(void)
+{
+ _testembed_Py_InitializeFromConfig();
+ PyThreadState_Swap(Py_NewInterpreter());
+ return PyRun_SimpleString("import readline"); // gh-124160
+}
+
+
/*****************************************************
* Test repeated initialisation and subinterpreters
*****************************************************/
@@ -2184,6 +2192,7 @@ static struct TestCase TestCases[] = {
{"test_repeated_init_exec", test_repeated_init_exec},
{"test_repeated_simple_init", test_repeated_simple_init},
{"test_forced_io_encoding", test_forced_io_encoding},
+ {"test_import_in_subinterpreters", test_import_in_subinterpreters},
{"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters},
{"test_repeated_init_and_inittab", test_repeated_init_and_inittab},
{"test_pre_initialization_api", test_pre_initialization_api},
diff --git a/Python/import.c b/Python/import.c
index 1056ddd370..be00c0b015 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2044,7 +2044,7 @@ import_run_extension(PyThreadState *tstate, PyModInitFunction p0,
singlephase.m_init = p0;
}
cached = update_global_state_for_extension(
- tstate, info->path, info->name, def, &singlephase);
+ main_tstate, info->path, info->name, def, &singlephase);
if (cached == NULL) {
assert(PyErr_Occurred());
goto main_finally;

View file

@ -14,10 +14,10 @@ URL: https://www.python.org/
# WARNING When rebasing to a new Python version,
# remember to update the python3-docs package as well
%global general_version %{pybasever}.0
%global prerel rc2
%global prerel rc3
%global upstream_version %{general_version}%{?prerel}
Version: %{general_version}%{?prerel:~%{prerel}}
Release: 3%{?dist}
Release: 1%{?dist}
License: Python-2.0.1
@ -390,14 +390,6 @@ Source11: idle3.appdata.xml
# pypa/distutils integration: https://github.com/pypa/distutils/pull/70
Patch251: 00251-change-user-install-location.patch
# 00439 # 5c3ace49fc6242246c8e54f2f904d483fb51aefa
# gh-122145: Handle an empty AST body when reporting tracebacks
Patch439: 00439-gh-122145-handle-an-empty-ast-body-when-reporting-tracebacks.patch
# 00440 # 7c35d4da60c9edc333a7031434bf114660e1ad34
# gh-124160: Pass main_tstate to update_global_state_for_extension()
Patch440: 00440-gh-124160-pass-main_tstate-to-update_global_state_for_extension.patch
# (New patches go here ^^^)
#
# When adding new patches to "python" and "python3" in Fedora, EL, etc.,
@ -1739,6 +1731,9 @@ CheckPython freethreading
# ======================================================
%changelog
* Tue Oct 01 2024 Miro Hrončok <mhroncok@redhat.com> - 3.13.0~rc3-1
- Update to Python 3.13.0rc3
* Thu Sep 19 2024 Miro Hrončok <mhroncok@redhat.com> - 3.13.0~rc2-3
- Fix segfault when trying to use PyRun_SimpleString() with some imports

View file

@ -1,2 +1,2 @@
SHA512 (Python-3.13.0rc2.tar.xz) = 85e6e6e80970ca38119e4f95880fb12e2d1548e6d60235cfcd7f6aaf08588c483469e43dda0f004b95455c2fb88ca736c313b22ae37eb0d4e6460ef521855c8d
SHA512 (Python-3.13.0rc2.tar.xz.asc) = 6d80d089b55910628744d21b0382b6441d0550c139dbee71d68a7cd9e494bff1c8235a2a894f3c7a52f9af312480a4001f333e04c9054f32db7eefd2a7d39263
SHA512 (Python-3.13.0rc3.tar.xz) = 152e5b6d64048c1779612e66d5999c424ca7c61c8a0f4973f7b3019629d6a7923b422aec0bee30e7bc2d589a807d87e15a19b8fb4446bcf082eb663885a49b36
SHA512 (Python-3.13.0rc3.tar.xz.asc) = c8f80b12f5e3021a11fc3ef5ce84572db9de7165ce89a03206cb0727b54f90ca2e444a16df064e6423e15b7bf2364db088b0c9315967dd340e735eabf7b892ce