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

[Python Console] Fix duplicated newline on save (windows) #52188

Merged
merged 1 commit into from
Mar 13, 2023

Conversation

YoannQDQ
Copy link
Contributor

Description

When saving a python script on Windows, newlines are duplicated.
This was introduced by #51913

On Windows, QScintilla inserts \r\n whenever the enter key is pressed. Code was previously reliant on the codecs.open, whose default handling of newlines differs from the way io.open, open, or Path does it.

This PR replaces the calls to

Path(name).write_text(text, encoding='utf-8')
with open(name, 'w', encoding='utf-8', newline='') as f:
   f.write(text)

Note: Path did not introduce the newline argument until Python 3.10 so we cannnot use it in this case.

@github-actions github-actions bot added the Python Console Python Console label Mar 12, 2023
@github-actions github-actions bot added this to the 3.32.0 milestone Mar 12, 2023
@YoannQDQ YoannQDQ added Bug Either a bug report, or a bug fix. Let's hope for the latter! Windows Related to Windows operating system labels Mar 12, 2023
@YoannQDQ YoannQDQ changed the title Fix duplicated newline on save (windows) [Python Console] Fix duplicated newline on save (windows) Mar 12, 2023
@nicogodet
Copy link
Member

Backport 3.30 ?

@YoannQDQ
Copy link
Contributor Author

Backport 3.30 ?

Definitely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Python Console Python Console Windows Related to Windows operating system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants