Mailing List Archive

[3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014)
https://github.com/python/cpython/commit/bbb1a8e7686353e1ae848ee77453195d1a6373e4
commit: bbb1a8e7686353e1ae848ee77453195d1a6373e4
branch: 3.12
author: Tian Gao <gaogaotiantian@hotmail.com>
committer: JelleZijlstra <jelle.zijlstra@gmail.com>
date: 2024-04-19T04:07:05Z
summary:

[3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014)

files:
A Misc/NEWS.d/next/Library/2024-04-17-23-38-06.gh-issue-117535.4Fgjlq.rst
M Lib/warnings.py

diff --git a/Lib/warnings.py b/Lib/warnings.py
index 391a501f7282eb..fc8c0128e3a1eb 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 00000000000000..2e664c70baa28a
--- /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`.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com