diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2024-04-19 03:50:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-19 03:50:09 (GMT) |
commit | a09e47299217fe98615aec8318e13a744307d52a (patch) | |
tree | 334ae7adde2cc710f5fc2b485977a9e85d0911b5 /Lib | |
parent | 398abdd6fa5b6b15c0570c75321cd7df9573a5b7 (diff) | |
download | cpython-a09e47299217fe98615aec8318e13a744307d52a.zip cpython-a09e47299217fe98615aec8318e13a744307d52a.tar.gz cpython-a09e47299217fe98615aec8318e13a744307d52a.tar.bz2 |
gh-117535: Change unknown filename of warnings from `sys` to `<sys>` (#118018)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 4 | ||||
-rw-r--r-- | Lib/warnings.py | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 50b0f3f..b768631 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -489,7 +489,7 @@ class WarnTests(BaseTest): warning_tests.inner("spam7", stacklevel=9999) self.assertEqual(os.path.basename(w[-1].filename), - "sys") + "<sys>") def test_stacklevel_import(self): # Issue #24305: With stacklevel=2, module-level warnings should work. @@ -1388,7 +1388,7 @@ a=A() # Issue #21925: Emitting a ResourceWarning late during the Python # shutdown must be logged. - expected = b"sys:1: ResourceWarning: unclosed file " + expected = b"<sys>:0: ResourceWarning: unclosed file " # don't import the warnings module # (_warnings will try to import it) diff --git a/Lib/warnings.py b/Lib/warnings.py index 4ad6ad0..20a39d5 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -332,8 +332,8 @@ def warn(message, category=None, stacklevel=1, source=None, raise ValueError except ValueError: globals = sys.__dict__ - filename = "sys" - lineno = 1 + filename = "<sys>" + lineno = 0 else: globals = frame.f_globals filename = frame.f_code.co_filename |