Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write stubs with utf-8 encoding #16329

Merged
merged 2 commits into from Oct 27, 2023
Merged

Write stubs with utf-8 encoding #16329

merged 2 commits into from Oct 27, 2023

Conversation

jorgen
Copy link
Contributor

@jorgen jorgen commented Oct 26, 2023

This is to ensure that you don't get encoding errors if docstrings contains odd characters like emojis.

This is to ensure that you don't get encoding errors if docstrings
contains odd characters like emojis.
@JelleZijlstra
Copy link
Member

Would you mind adding a test that includes a non-ASCII character in a docstring?

@jorgen
Copy link
Contributor Author

jorgen commented Oct 26, 2023

I had a short stab at adding a unit test. Simplest test of this as I can tell is to add it to the stubgen.test, but I'm having a hard time running this. Simplest example of showing the problem is

with open("test", "w") as f:
    f.write("\U0001F60A")

Adding encoding="utf-8" to this fixes the problem. This is on Windows. On Linux I would not imagin this being a problem.

The workaround for this is setting PYTHONUTF8=1 but I spent some time finding this, and I imagined the patch it would save someone else this time.

@JelleZijlstra JelleZijlstra merged commit 4f05dd5 into python:master Oct 27, 2023
13 checks passed
@jorgen
Copy link
Contributor Author

jorgen commented Oct 27, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants