diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2024-04-19 04:07:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-19 04:07:05 (GMT) |
commit | bbb1a8e7686353e1ae848ee77453195d1a6373e4 (patch) | |
tree | 4d3820a3b00cbdc7f8b9b774244ee5d4fa778355 /Lib | |
parent | 632f353d9e16645db58a6d4989486ebf2c5650b8 (diff) | |
download | cpython-bbb1a8e7686353e1ae848ee77453195d1a6373e4.zip cpython-bbb1a8e7686353e1ae848ee77453195d1a6373e4.tar.gz cpython-bbb1a8e7686353e1ae848ee77453195d1a6373e4.tar.bz2 |
[3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/warnings.py | 4 |
1 files changed, 3 insertions, 1 deletions
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) |