From 11f1dd128613ede60dbf3ee6f6a591d3ce3b0c7f Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 17 Apr 2024 16:35:06 -0700 Subject: [PATCH 1/3] Ignore makeup file name "sys" for warnings --- Lib/warnings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/warnings.py b/Lib/warnings.py index 391a501f7282eb..884e91761914ca 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 8889326b92b36a6ebd6245f059e84ce93a6eb51a Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:38:07 +0000 Subject: [PATCH 2/3] =?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-17-23-38-06.gh-issue-117535.4Fgjlq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst diff --git a/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst b/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst new file mode 100644 index 00000000000000..9a896ab7abada7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst @@ -0,0 +1 @@ +Do not try to get the source line for makeup file name "sys" in :mod:`warnings` From 23a26d3291879637a90739573923a17a7afe014e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 18 Apr 2024 20:51:57 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- Lib/warnings.py | 2 +- .../next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/warnings.py b/Lib/warnings.py index 884e91761914ca..fc8c0128e3a1eb 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -36,7 +36,7 @@ def _formatwarnmsg_impl(msg): category = msg.category.__name__ s = f"{msg.filename}:{msg.lineno}: {category}: {msg.message}\n" - # "sys" is a makeup file name when we are not able to get the frame + # "sys" is a made up 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: diff --git a/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst b/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst index 9a896ab7abada7..2e664c70baa28a 100644 --- a/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst +++ b/Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst @@ -1 +1 @@ -Do not try to get the source line for makeup file name "sys" in :mod:`warnings` +Do not try to get the source line for made up file name "sys" in :mod:`warnings`.