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

Fix encoding issue in file writing to handle Non-ASCII characters #312

Closed
wants to merge 0 commits into from

Conversation

splendid-pilot
Copy link
Contributor

Description:
This PR fixes a UnicodeEncodeError in line_profiler when profiling functions with non-ASCII characters (e.g., CJK characters) in function names or docstrings. The error occurs on Windows due to the default cp1252 encoding not supporting such characters.

Solution: The fix explicitly sets encoding='utf-8' in the write_text function calls in explicit_profiler.py, ensuring proper handling of non-ASCII characters during profiling output.

Why:
Ensures line_profiler works correctly with CJK and other non-ASCII characters, especially on Windows systems.
Prevents crashes when profiling functions with non-Latin characters in their names or docstrings.
image

@Erotemic
Copy link
Member

Ah Windows encoding issues. Such a pain.

LGTM. I'll merge once dashboards pass.

@Erotemic
Copy link
Member

I need to merge the 1.4.2 branch, after that point we will rebase on top of main and then add a CHANGELOG note. Then this will be merged into main and be part of the next patch release.

By default I'll wait for other PRs before I make a release, but if this is causing day-to-day issues, let me know and I can expedite the process.

@Erotemic
Copy link
Member

did not mean to close this, reopened here: #313

@splendid-pilot
Copy link
Contributor Author

No problem at all, and thank you for addressing the issue. I’ve already applied the change in my local environment, so there’s no need to expedite the process. Thanks again for your time and for maintaining this great project!

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.

2 participants