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

bpo-41373: IDLE: Fix saving files loaded with no newlines or mixed newlines #21597

Merged
merged 4 commits into from
Jul 25, 2020

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 23, 2020

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to make two changes other than the one in the comment below.

  1. Line 140 'Will utf-8 decode'. Replace with encoding might be unknown rather than wrong.

  2. UnicodeDecodeError on 152 can now only come from the 2nd read in 144-9.

Add to this PR? Separate PR for this issue? Separate issue?

if not isinstance(eol_convention, str):
# If the file does not contain line separators, it is None.
# If the file contains mixed line separators, it is a tuple.
eol_convention = os.linesep # default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 124 above is identical, except it sets eol_convention as a class attribute. The class attribute is used in fixnewlines (the only usage) for new files created in IDLE. Rather than duplicate the default, I would rather only set the instance attribute when it might not be the default.

if isinstance(eol_convention, str):
    self.eol_convention = eol_convention  # Line 172 below.
else:
    # If .... None.
    # If ... tuple.
    if eol_convention is not None:
        # Message box as below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you call loadfile() for the same edit window second time, eol_convention will be set to the EOL convention in previously opened file,

Copy link
Member

@terryjreedy terryjreedy Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, I don't think loadfile() is ever called more than once for an edit window*. Which means that the later line deleting current content is a no-op. But I would like to add a 'reload' function, such an when one want to restart editing, or a file is changed externally. So I agree with leaving loadfile as is, ready for such an addition.

*Except in the htest for iomenu, and I want that to continue to work.

However, the line changing eol_convention from None/tuple to string must be moved after the test for it being tuple (not None). As it is, editing a blank file brings up a spurious mixed endings message. I will change this and add a blurb.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

AFAIK loadfile() is called for the same edit window when you pick a recent file from menu.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recent files not already being edited are loaded in a new window, leaving current windows alone. Asking for a file already loaded switches to its window. What I would like to add is a popup offering to discard changes and reload.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@serhiy-storchaka
Copy link
Member Author

Add to this PR? Separate PR for this issue? Separate issue?

I did not fully understand you, but I think it is a separate issue.

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@terryjreedy
Copy link
Member

I will leave other changes to another issue after adding tests in a followup PR. I tested this change after the line was moved by loading and saving both a blank file and one with different endings, and reloading the result of the latter and checking that it only had default endings. I added blurb and will merge when CI done.

@terryjreedy terryjreedy merged commit 0dd463c into python:master Jul 25, 2020
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR, and @terryjreedy for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 25, 2020
…wlines (pythonGH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
(cherry picked from commit 0dd463c)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot
Copy link

GH-21610 is a backport of this pull request to the 3.9 branch.

@bedevere-bot
Copy link

GH-21611 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 25, 2020
…wlines (pythonGH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
(cherry picked from commit 0dd463c)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington added a commit that referenced this pull request Jul 25, 2020
…wlines (GH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
(cherry picked from commit 0dd463c)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington added a commit that referenced this pull request Jul 25, 2020
…wlines (GH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
(cherry picked from commit 0dd463c)

Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka serhiy-storchaka deleted the idle-eol-convention branch July 26, 2020 07:22
@serhiy-storchaka
Copy link
Member Author

Thank you for adding blurb Terry.

shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 4, 2020
…wlines (pythonGH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
…wlines (pythonGH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
…wlines (pythonGH-21597)

Fixes regression in 3.8.4 and 3.9.0b4.

Co-authored-by: Terry Jan Reedy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants