[3.14] gh-139640: Fix swallowing syntax warnings in different modules (GH-139755) (GH-140117)

Revert GH-131993.

Fix swallowing some syntax warnings in different modules if they accidentally
have the same message and are emitted from the same line.

Fix duplicated warnings in the "finally" block.

(cherry picked from commit 279db6bede)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

* Update 2025-10-06-10-03-37.gh-issue-139640.gY5oTb.rst

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-10-14 17:56:01 +02:00 committed by GitHub
parent 99e42ab49c
commit af28efd8b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 63 additions and 74 deletions

View file

@ -1938,8 +1938,8 @@ int
_PyErr_EmitSyntaxWarning(PyObject *msg, PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
{
if (_PyErr_WarnExplicitObjectWithContext(PyExc_SyntaxWarning, msg,
filename, lineno) < 0)
if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg,
filename, lineno, NULL, NULL) < 0)
{
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
/* Replace the SyntaxWarning exception with a SyntaxError