-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-83847: IDLE - Refactor common code between hyperparser and editor #18539
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
Conversation
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 approve in principle, subject to more review and a couple of possible changes (so far).
|
||
if self.prompt_last_line: | ||
r = text.tag_prevrange("console", index) | ||
startatindex = r[1] if r else "1.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.
'1.0', copied from the old code, seems wrong, as it is the Shell top, before the sign-in message, let alone the first prompt. If one hits Enter at the prompt, I would think that the code should be set to '\n'.
I need to add some prints to be sure of what happens in Shell and editor with various inputs.
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.
In the shell, it looks like it will always find the last console
tag, which is marked from the beginning to the end of the prompt. For example, in a new shell window, typing >>> def hello(
without pressing Enter shows r
to be (3.0, 3.4)
.
I wasn't able to think of a scenario where the prompt would be missing in a real shell, so I'm not sure if the default of 1.0
would ever be used there. However, adding a print(r)
and running the testsuite shows that the console tag isn't set for most tests, so it falls back to the default.
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.
Then the shell tests are unrealistic. Of course, with the prompt moved to a sidebar, we should be looking, I believe, for a mark.
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.
Of course, with the prompt moved to a sidebar, we should be looking, I believe, for a mark.
With the shell moved to a sidebar (PR GH-15474), there's still a "console" tag on the newline (\n
) before the beginning of the current input block, making code such as this continue to "just work".
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.
While we're refactoring this, I think it's a great opportunity to remove the shell-specific part of this code from the EditorWindow class and into PyShell.
When you're done making the requested changes, leave the comment: |
I have made the requested changes; please review again |
Thanks for making the requested changes! @terryjreedy: please review the changes made to this pull request. |
* Move num_context_lines into editor.parser method since it's not used anywhere else.
To properly review this, I need to look at EditorWindow chunk, Hyperparser chunk, and new function side-by-side when I have more time. Also see reply on the issue re location of new function. |
Closing because I currently prefer #20847 with the new function in hyperparser. |
hyperparser.py
andeditor.py
for creating a Parser instance that is used for analysis.hyperparser
before.