]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129843: fix pure Python implementation of `warnings.warn_explicit` (#129848)
authorSrinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) <thatiparthysreenivas@gmail.com>
Mon, 17 Mar 2025 10:49:53 +0000 (16:19 +0530)
committerGitHub <noreply@github.com>
Mon, 17 Mar 2025 10:49:53 +0000 (10:49 +0000)
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`).

Lib/warnings.py
Misc/NEWS.d/next/Library/2025-03-17-15-45-36.gh-issue-129843.NPdpXL.rst [new file with mode: 0644]

index 13ad6c8aacbb7fd66fe586c880964b2dc1344da7..df844253ab4e6d5887ad1efbbbecb7b2b2bed6a8 100644 (file)
@@ -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 (file)
index 0000000..c16d615
--- /dev/null
@@ -0,0 +1 @@
+Fix incorrect argument passing in :func:`warnings.warn_explicit`.