https://github.com/python/cpython/commit/b42fdf6b44b6701dc643c733983fff4500e077c4
commit: b42fdf6b44b6701dc643c733983fff4500e077c4
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-03T15:37:58+02:00
summary:

Fix _PyOS_GetOpt() error message for non-ASCII characters (#158626)

Replace %c with %lc.

files:
M Lib/test/test_cmd_line.py
M Python/getopt.c

diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 6d07238a9d08ab..1e303dc3bf6770 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 45454d39fc6779..2dcabc9962d25f 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 '_';
             }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to