]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014)
authorTian Gao <gaogaotiantian@hotmail.com>
Fri, 19 Apr 2024 04:07:05 +0000 (21:07 -0700)
committerGitHub <noreply@github.com>
Fri, 19 Apr 2024 04:07:05 +0000 (04:07 +0000)
Lib/warnings.py
Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst [new file with mode: 0644]

index 391a501f7282eb0effd782e2ed5b66615305e2c6..fc8c0128e3a1eb04e0ad61fe94e565bf3fee41ca 100644 (file)
@@ -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 (file)
index 0000000..2e664c7
--- /dev/null
@@ -0,0 +1 @@
+Do not try to get the source line for made up file name "sys" in :mod:`warnings`.