From 23a12c29d9d00e1e9cac6ba6bd48e0c16972bf58 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 17 Apr 2024 17:31:58 -0700 Subject: [PATCH 1/3] Change unknown filename of warnings from sys to --- Lib/test/test_warnings/__init__.py | 4 ++-- Lib/warnings.py | 2 +- Python/_warnings.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 50b0f3fff04c57..a55cc0ba0abd32 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -489,7 +489,7 @@ def test_stacklevel(self): warning_tests.inner("spam7", stacklevel=9999) self.assertEqual(os.path.basename(w[-1].filename), - "sys") + "") def test_stacklevel_import(self): # Issue #24305: With stacklevel=2, module-level warnings should work. @@ -1388,7 +1388,7 @@ def test_late_resource_warning(self): # Issue #21925: Emitting a ResourceWarning late during the Python # shutdown must be logged. - expected = b"sys:1: ResourceWarning: unclosed file " + expected = b":1: 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 4ad6ad027192e8..3de4ad9c961bbf 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -332,7 +332,7 @@ def warn(message, category=None, stacklevel=1, source=None, raise ValueError except ValueError: globals = sys.__dict__ - filename = "sys" + filename = "" lineno = 1 else: globals = frame.f_globals diff --git a/Python/_warnings.c b/Python/_warnings.c index 4c520252aa12a8..3fdcf3b8ac3ea4 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -894,7 +894,7 @@ setup_context(Py_ssize_t stack_level, if (f == NULL) { globals = interp->sysdict; - *filename = PyUnicode_FromString("sys"); + *filename = PyUnicode_FromString(""); *lineno = 1; } else { From 90bcff3de09af7fd3c1768742bbae0acf4d43852 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:35:13 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-04-18-00-35-11.gh-issue-117535.0m6SIM.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-04-18-00-35-11.gh-issue-117535.0m6SIM.rst diff --git a/Misc/NEWS.d/next/Library/2024-04-18-00-35-11.gh-issue-117535.0m6SIM.rst b/Misc/NEWS.d/next/Library/2024-04-18-00-35-11.gh-issue-117535.0m6SIM.rst new file mode 100644 index 00000000000000..72423506ccc07b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-04-18-00-35-11.gh-issue-117535.0m6SIM.rst @@ -0,0 +1 @@ +Change the unknown filename of :mod:`warnings` from ``sys`` to ```` to clarify that it's not a real filename. From a1524ac7d0011f2a0f0acbee83b9c6ccac85a66d Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 18 Apr 2024 10:37:53 -0700 Subject: [PATCH 3/3] Change lineno to 0 --- Lib/test/test_warnings/__init__.py | 2 +- Lib/warnings.py | 2 +- Python/_warnings.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index a55cc0ba0abd32..b768631846e240 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -1388,7 +1388,7 @@ def test_late_resource_warning(self): # Issue #21925: Emitting a ResourceWarning late during the Python # shutdown must be logged. - expected = b":1: ResourceWarning: unclosed file " + expected = b":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 3de4ad9c961bbf..20a39d54bf7e6a 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -333,7 +333,7 @@ def warn(message, category=None, stacklevel=1, source=None, except ValueError: globals = sys.__dict__ filename = "" - lineno = 1 + lineno = 0 else: globals = frame.f_globals filename = frame.f_code.co_filename diff --git a/Python/_warnings.c b/Python/_warnings.c index 3fdcf3b8ac3ea4..2ba704dcaa79b2 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -895,7 +895,7 @@ setup_context(Py_ssize_t stack_level, if (f == NULL) { globals = interp->sysdict; *filename = PyUnicode_FromString(""); - *lineno = 1; + *lineno = 0; } else { globals = f->f_frame->f_globals;