mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
gh-117535: Change unknown filename of warnings from sys
to <sys>
(#118018)
This commit is contained in:
parent
398abdd6fa
commit
a09e472992
4 changed files with 7 additions and 6 deletions
|
@ -489,7 +489,7 @@ class WarnTests(BaseTest):
|
||||||
|
|
||||||
warning_tests.inner("spam7", stacklevel=9999)
|
warning_tests.inner("spam7", stacklevel=9999)
|
||||||
self.assertEqual(os.path.basename(w[-1].filename),
|
self.assertEqual(os.path.basename(w[-1].filename),
|
||||||
"sys")
|
"<sys>")
|
||||||
|
|
||||||
def test_stacklevel_import(self):
|
def test_stacklevel_import(self):
|
||||||
# Issue #24305: With stacklevel=2, module-level warnings should work.
|
# 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
|
# Issue #21925: Emitting a ResourceWarning late during the Python
|
||||||
# shutdown must be logged.
|
# shutdown must be logged.
|
||||||
|
|
||||||
expected = b"sys:1: ResourceWarning: unclosed file "
|
expected = b"<sys>:0: ResourceWarning: unclosed file "
|
||||||
|
|
||||||
# don't import the warnings module
|
# don't import the warnings module
|
||||||
# (_warnings will try to import it)
|
# (_warnings will try to import it)
|
||||||
|
|
|
@ -332,8 +332,8 @@ def warn(message, category=None, stacklevel=1, source=None,
|
||||||
raise ValueError
|
raise ValueError
|
||||||
except ValueError:
|
except ValueError:
|
||||||
globals = sys.__dict__
|
globals = sys.__dict__
|
||||||
filename = "sys"
|
filename = "<sys>"
|
||||||
lineno = 1
|
lineno = 0
|
||||||
else:
|
else:
|
||||||
globals = frame.f_globals
|
globals = frame.f_globals
|
||||||
filename = frame.f_code.co_filename
|
filename = frame.f_code.co_filename
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Change the unknown filename of :mod:`warnings` from ``sys`` to ``<sys>`` to clarify that it's not a real filename.
|
|
@ -894,8 +894,8 @@ setup_context(Py_ssize_t stack_level,
|
||||||
|
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
globals = interp->sysdict;
|
globals = interp->sysdict;
|
||||||
*filename = PyUnicode_FromString("sys");
|
*filename = PyUnicode_FromString("<sys>");
|
||||||
*lineno = 1;
|
*lineno = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
globals = f->f_frame->f_globals;
|
globals = f->f_frame->f_globals;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue