From bbb1a8e7686353e1ae848ee77453195d1a6373e4 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 18 Apr 2024 21:07:05 -0700 Subject: [3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014) --- Lib/warnings.py | 4 +++- .../next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst diff --git a/Lib/warnings.py b/Lib/warnings.py index 391a501..fc8c012 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 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: import linecache line = linecache.getline(msg.filename, msg.lineno) 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 0000000..2e664c7 --- /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 made up file name "sys" in :mod:`warnings`. -- cgit v0.12