]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-142037: Improve error messages for printf-style formatting (GH-142081)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 24 Jan 2026 11:13:50 +0000 (13:13 +0200)
committerGitHub <noreply@github.com>
Sat, 24 Jan 2026 11:13:50 +0000 (11:13 +0000)
commit012c498035a9adfe9fd218907db1550ecb057f77
tree54b1fda8788cbe053a00c357d046c35af42ec8ec
parent5f736a0432c2e43de8f35d9a75aa814e4407e637
gh-142037: Improve error messages for printf-style formatting (GH-142081)

This affects string formatting as well as bytes and bytearray formatting.

* For errors in the format string, always include the position of the
  start of the format unit.
* For errors related to the formatted arguments, always include the number
  or the name of the formatted argument.
* Suggest more probable causes of errors in the format string (stray %,
  unsupported format, unexpected character).
* Provide more information when the number of arguments does not match
  the number of format units.
* Raise more specific errors when access of arguments by name is mixed with
  sequential access and when * is used with a mapping.
* Add tests for some uncovered cases.
Lib/test/test_bytes.py
Lib/test/test_format.py
Lib/test/test_peepholer.py
Lib/test/test_str.py
Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-10-06-06.gh-issue-142037.OpIGzK.rst [new file with mode: 0644]
Objects/bytesobject.c
Objects/unicode_format.c