From f81c8c07e488d4d5052a9668a363de4060b65f40 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 4 Apr 2024 10:56:51 -0700 Subject: [PATCH 1/2] Do not try to get the source line for file "sys" in warnings --- Lib/warnings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/warnings.py b/Lib/warnings.py index 4ad6ad027192e8..ff8df7304694f2 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -36,7 +36,9 @@ def _formatwarnmsg_impl(msg): category = msg.category.__name__ s = f"{msg.filename}:{msg.lineno}: {category}: {msg.message}\n" - if msg.line is None: + # "sys" is a makeup file name when we are not able to get the frame + # so do not try to get the source line + if msg.line is None and msg.filename != "sys": try: import linecache line = linecache.getline(msg.filename, msg.lineno) From fa8dc7b8cc350037777f28d03778e180db14893c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 18:07:12 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-04-04-18-07-10.gh-issue-117535.4Fgjlq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-04-04-18-07-10.gh-issue-117535.4Fgjlq.rst diff --git a/Misc/NEWS.d/next/Library/2024-04-04-18-07-10.gh-issue-117535.4Fgjlq.rst b/Misc/NEWS.d/next/Library/2024-04-04-18-07-10.gh-issue-117535.4Fgjlq.rst new file mode 100644 index 00000000000000..9a896ab7abada7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-04-04-18-07-10.gh-issue-117535.4Fgjlq.rst @@ -0,0 +1 @@ +Do not try to get the source line for makeup file name "sys" in :mod:`warnings`