Skip to content

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

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:getopt_lc
Oct 3, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:getopt_lc

Conversation

@vstinner

@vstinner vstinner commented Oct 2, 2026

Copy link
Copy Markdown
Member

Replace %c with %lc.

@vstinner
vstinner merged commit b42fdf6 into python:main Oct 3, 2026
57 checks passed
@vstinner
vstinner deleted the getopt_lc branch October 3, 2026 13:38
@vstinner

vstinner commented Oct 3, 2026

Copy link
Copy Markdown
Member Author

I didn't write tests since assert_python_failure() returns bytes and it's not easy to get the right encoding. On Windows, it seems like print("%lc") uses the locale encoding which can be "cp1252" for example, it's not UTF-8. The strange thing is that on Windows, python -é displays the error message correctly (I tested cmd and powershell terminals). If a test is added later, I would suggest using locale.getencoding() to decode stderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant