From: Tian Gao Date: Fri, 19 Apr 2024 04:07:05 +0000 (-0700) Subject: [3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014) X-Git-Tag: v3.12.4~200 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbb1a8e7686353e1ae848ee77453195d1a6373e4;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014) --- diff --git a/Lib/warnings.py b/Lib/warnings.py index 391a501f7282..fc8c0128e3a1 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 000000000000..2e664c70baa2 --- /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`.