-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-44968: Add "Reload from Disk" feature to IDLE #141574
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
base: main
Are you sure you want to change the base?
Conversation
sharktide
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don’t think we should restore the cursor position since a file’s line numbers could also change when it is edited and it could cause confusion.
Co-authored-by: R.C.M <sharktidedev@gmail.com>
Removed cursor position restoration logic during file reload.
Rewrote it, now it won't save cursor position. |
picnixz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rely more on unittest.mock.patch() as well as mock features directly. In addition add a What's New entry in addition to the NEWS entry.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I have made the requested changes; please review again |
Co-authored-by: R.C.M <sharktidedev@gmail.com>
Misc/NEWS.d/next/IDLE/2025-11-14-20-58-55.gh-issue-44968.rL9dK3.rst
Outdated
Show resolved
Hide resolved
…3.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
You don't need to keep updating the branch because we all get emails and it uses up ci time unless its been really long or unrelated tests fail. When merging, git usually can handle it automatically unless you see that there are conflicts |
Co-authored-by: R.C.M <sharktidedev@gmail.com>
Co-authored-by: R.C.M <sharktidedev@gmail.com>
picnixz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, your PRs always take me long to review because there are unrelated changes, or un-necessary things that are introduced. It's really not the first time. Carefully read the devguide and honestly, avoid using an LLM. If you are worried about NEWS writing, leave it blank and ask someone else to write it for you. But for the code, there are many places where I feel it's been LLM-generated. In general:
- Never remove code that is not related to the issue you are fixing.
- Never add type annotations.
- Never make unrelated changes.
- Read the devguide.
- Don't add trivial comments. Usually this is a sign that an LLM has been used.
- Follow PEP-8. In particular, wrap your code under the 80-char mark.
| shelltext = '>>> if 1' | ||
| self.editwin.get_prompt_text = Func(result=shelltext) | ||
| eq(fix(), shelltext) # Get... call and '\n' not added. | ||
| eq(fix(), shelltext) # Get... call and '\n' not added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this will be the last time I'm going to say this but please never change unrelated code. Do not use an autoformatter, or configure your IDE so that it doesn't autoformat on save, or ask your LLM not to do any change.
| (Contributed by Nick Burns and Senthil Kumaran in :gh:`92936`.) | ||
|
|
||
|
|
||
| idlelib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@terryjreedy For IDLE changes, do we add it here or somewhere else in general?
| with patch('idlelib.iomenu.messagebox.showinfo') as mock_showinfo: | ||
| result = io.reload(None) | ||
| self.assertEqual(result, "break") | ||
| mock_showinfo.assert_called_once() | ||
| args, kwargs = mock_showinfo.call_args | ||
| self.assertIn("File Not Found", args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| with patch('idlelib.iomenu.messagebox.showinfo') as mock_showinfo: | |
| result = io.reload(None) | |
| self.assertEqual(result, "break") | |
| mock_showinfo.assert_called_once() | |
| args, kwargs = mock_showinfo.call_args | |
| self.assertIn("File Not Found", args[0]) | |
| with patch('idlelib.iomenu.messagebox.showinfo') as mock_showinfo: | |
| result = io.reload(None) | |
| self.assertEqual(result, "break") | |
| mock_showinfo.assert_called_once() | |
| args, _ = mock_showinfo.call_args | |
| self.assertIn("File Not Found", args[0]) |
| io.loadfile(io.filename) | ||
| self.assertEqual(text.get('1.0', 'end-1c'), original_content) | ||
|
|
||
| with builtins.open(filename, 'w', encoding='utf-8') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using builtins.open now that you have tokenize_open?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure tokenize_open can only open the file in read mode here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about tokenize_open. It's about just using the plain open. There is no need to use builtins.open now that open is not shadowed.
| fd, filename = tempfile.mkstemp(suffix='.py') | ||
| os.close(fd) | ||
| self.addCleanup(os.unlink, filename) | ||
| with builtins.open(filename, 'w', encoding='utf-8') as f: | ||
| f.write(content) | ||
| return filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fd, filename = tempfile.mkstemp(suffix='.py') | |
| os.close(fd) | |
| self.addCleanup(os.unlink, filename) | |
| with builtins.open(filename, 'w', encoding='utf-8') as f: | |
| f.write(content) | |
| return filename | |
| filename = tempfile.mktemp() | |
| self.addCleanup(os_helper.unlink, filename) | |
| with open(filename, "w") as f: | |
| f.write(content) | |
| return filename |
We don't care about secure temporary file for a test.
| cls.root.destroy() | ||
| del cls.root | ||
|
|
||
| def _create_tempfile(self, content: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use type annotations.
| text.insert('end', "\n# Unsaved change") | ||
| io.set_saved(False) | ||
|
|
||
| with patch('idlelib.iomenu.messagebox.askokcancel', return_value=False) as mock_ask: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap lines under 80 chars.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
sharktide
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added commit suggestions based on picnixz's comments, also added one suggestion for the news entry
| cls.root.destroy() | ||
| del cls.root | ||
|
|
||
| def _create_tempfile(self, content: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def _create_tempfile(self, content: str) -> str: | |
| def _create_tempfile(self, content): |
| shelltext = '>>> if 1' | ||
| self.editwin.get_prompt_text = Func(result=shelltext) | ||
| eq(fix(), shelltext) # Get... call and '\n' not added. | ||
| eq(fix(), shelltext) # Get... call and '\n' not added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| eq(fix(), shelltext) # Get... call and '\n' not added. | |
| eq(fix(), shelltext) # Get... call and '\n' not added. |
| @@ -0,0 +1,3 @@ | |||
| Add "Reload from Disk" menu item to IDLE's File menu. This allows users to | |||
| easily reload a file from disk, discarding any unsaved changes in the editor. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| easily reload a file from disk, discarding any unsaved changes in the editor. | |
| reload a file from disk, discarding unsaved changes in the editor. |
Remove unnecessary words
| self.text.focus_set() | ||
| return "break" | ||
|
|
||
| # Reload the file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Reload the file |
Trivial comment
| text.insert('end', "\n# Unsaved change") | ||
| io.set_saved(False) | ||
|
|
||
| with patch('idlelib.iomenu.messagebox.askokcancel', return_value=False) as mock_ask: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| with patch('idlelib.iomenu.messagebox.askokcancel', return_value=False) as mock_ask: | |
| with patch('idlelib.iomenu.messagebox.askokcancel', | |
| return_value=False) as mock_ask: |
| io.loadfile(io.filename) | ||
| self.assertEqual(text.get('1.0', 'end-1c'), original_content) | ||
|
|
||
| with builtins.open(filename, 'w', encoding='utf-8') as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure tokenize_open can only open the file in read mode here
Uh oh!
There was an error while loading. Please reload this page.