Skip to content

Commit bbb1a8e

Browse files
[3.12] gh-117535: Ignore made up file name "sys" for warnings (#118014)
1 parent 632f353 commit bbb1a8e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/warnings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def _formatwarnmsg_impl(msg):
3636
category = msg.category.__name__
3737
s = f"{msg.filename}:{msg.lineno}: {category}: {msg.message}\n"
3838

39-
if msg.line is None:
39+
# "sys" is a made up file name when we are not able to get the frame
40+
# so do not try to get the source line
41+
if msg.line is None and msg.filename != "sys":
4042
try:
4143
import linecache
4244
line = linecache.getline(msg.filename, msg.lineno)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not try to get the source line for made up file name "sys" in :mod:`warnings`.

0 commit comments

Comments
 (0)