From 57f69d921b2bfc90867a1dcc738355085bec8d3f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 2 Oct 2026 23:12:18 +0200 Subject: [PATCH] Fix _PyOS_GetOpt() error message for non-ASCII characters Replace %c with %lc. --- Lib/test/test_cmd_line.py | 2 +- Python/getopt.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 6d07238a9d08abf..1e303dc3bf67705 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -684,7 +684,7 @@ def test_del___main__(self): @support.cpython_only def test_unknown_options(self): - # Test unknown option -a + # Test unknown option for option in ('-z', '--long-option', '---'): with self.subTest(option=option): rc, out, err = assert_python_failure('-E', option) diff --git a/Python/getopt.c b/Python/getopt.c index 45454d39fc67792..2dcabc9962d25f3 100644 --- a/Python/getopt.c +++ b/Python/getopt.c @@ -160,7 +160,7 @@ _PyOS_GetOpt(struct _PyOS_GetOpt *getopt) wchar_t *ptr = wcschr(SHORT_OPTS, option); if (ptr == NULL) { if (error) { - fprintf(stderr, "Unknown option: -%c\n", (char)option); + fprintf(stderr, "Unknown option: -%lc\n", option); } return '_'; } @@ -174,7 +174,7 @@ _PyOS_GetOpt(struct _PyOS_GetOpt *getopt) if (getopt->index >= argc) { if (error) { fprintf(stderr, - "Argument expected for the -%c option\n", (char)option); + "Argument expected for the -%lc option\n", option); } return '_'; }