From: Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) Date: Mon, 17 Mar 2025 10:49:53 +0000 (+0530) Subject: gh-129843: fix pure Python implementation of `warnings.warn_explicit` (#129848) X-Git-Tag: v3.14.0a7~355 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80e00ecc399db8aeaa9f3a1c87a2cfb34517d7be;p=thirdparty%2FPython%2Fcpython.git gh-129843: fix pure Python implementation of `warnings.warn_explicit` (#129848) The pure Python implementation of `warnings.warn_explicit` constructs a `WarningMessage` with an incorrect source (it incorrectly sets the WarningMessage's line to the given `source`). --- diff --git a/Lib/warnings.py b/Lib/warnings.py index 13ad6c8aacbb..df844253ab4e 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -422,7 +422,7 @@ def warn_explicit(message, category, filename, lineno, linecache.getlines(filename, module_globals) # Print message and context - msg = WarningMessage(message, category, filename, lineno, source) + msg = WarningMessage(message, category, filename, lineno, source=source) _showwarnmsg(msg) diff --git a/Misc/NEWS.d/next/Library/2025-03-17-15-45-36.gh-issue-129843.NPdpXL.rst b/Misc/NEWS.d/next/Library/2025-03-17-15-45-36.gh-issue-129843.NPdpXL.rst new file mode 100644 index 000000000000..c16d61540edf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-17-15-45-36.gh-issue-129843.NPdpXL.rst @@ -0,0 +1 @@ +Fix incorrect argument passing in :func:`warnings.warn_explicit`.