From 526f5c365d0791d4a1a0e2cd417a1118bcea8206 Mon Sep 17 00:00:00 2001 From: AZero13 Date: Fri, 26 Dec 2025 17:19:18 -0500 Subject: [PATCH] gh-143201: warnings writes the full source line instead of the truncated one The truncated object is meant to be written instead. --- .../2025-12-26-17-18-18.gh-issue-143201.UbXuX4.rst | 1 + Python/_warnings.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-12-26-17-18-18.gh-issue-143201.UbXuX4.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-12-26-17-18-18.gh-issue-143201.UbXuX4.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-26-17-18-18.gh-issue-143201.UbXuX4.rst new file mode 100644 index 00000000000000..14ec47fa432e9f --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-26-17-18-18.gh-issue-143201.UbXuX4.rst @@ -0,0 +1 @@ +Print out the truncated line, not the raw sourceline. diff --git a/Python/_warnings.c b/Python/_warnings.c index d44d414bc93a04..1e9d88849bc219 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -697,7 +697,7 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno, if (truncated == NULL) goto error; - PyFile_WriteObject(sourceline, f_stderr, Py_PRINT_RAW); + PyFile_WriteObject(truncated, f_stderr, Py_PRINT_RAW); Py_DECREF(truncated); PyFile_WriteString("\n", f_stderr); }