mirror of https://github.com/python/cpython
gh-117535: Change unknown filename of warnings from `sys` to `<sys>` (#118018)
This commit is contained in:
parent
398abdd6fa
commit
a09e472992
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
globals = interp->sysdict;
|
||||
*filename = PyUnicode_FromString("sys");
|
||||
*lineno = 1;
|
||||
*filename = PyUnicode_FromString("<sys>");
|
||||
*lineno = 0;
|
||||
}
|
||||
else {
|
||||
globals = f->f_frame->f_globals;
|
||||
|
|
Loading…
Reference in New Issue