-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-38673: dont switch to ps2 if the line starts with comment or whitespace #17421
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
|
The patch fixes the issue on master on Windows. I can't tell if this is the best fix or if there could be an issue not caught in the tests. |
gvanrossum
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'm not sure that this is the right approach yet. While you prevent the prompt from changing to "...", the code still keeps accumulating input, which means the line count will be off. Example:
>>> #
>>> )
File "<stdin>", line 2
SyntaxError: unmatched ')'
I suspect you may have to doctor the caller of tok_nextc(), or perhaps its caller...
c9d117e to
ecf7b35
Compare
|
Thanks for suggestions @gvanrossum, current version fixed accumulation bug. |
Parser/tokenizer.c
Outdated
| if (tok->nextprompt != NULL) | ||
| tok->prompt = tok->nextprompt; | ||
| if (tok->nextprompt != NULL) { | ||
| if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t')) |
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.
PEP 7: Please add braces
Parser/tokenizer.c
Outdated
| if (tok->nextprompt != NULL) { | ||
| if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t')) | ||
| tok->nextprompt = NULL; | ||
| else |
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.
PEP 7: Please add braces
Misc/NEWS.d/next/Core and Builtins/2019-12-01-00-17-44.bpo-38673.K_Tze-.rst
Outdated
Show resolved
Hide resolved
Parser/tokenizer.c
Outdated
| if (tok->nextprompt != NULL) | ||
| tok->prompt = tok->nextprompt; | ||
| if (tok->nextprompt != NULL) { | ||
| if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t')) |
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.
Suggestion: You may be able to simplify this with strchr (check that is not slower....maybe is faster if inlined).
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.
Thank you for suggestions, I'll apply them.
|
Left some comment regarding the code itself, I didn't check the solution itself yet. |
|
(I am working through a backlog, I should pay attention to reviews and other tasks that have been waiting longer first.) |
0b0fb24 to
5e632fb
Compare
gvanrossum
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.
Better, but there's still a regression. Look here:
Python 3.9.0a1+ (heads/pr/17421:5e632fb43a, Dec 6 2019, 14:23:30)
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if 1:
... # comment
File "<stdin>", line 2
# comment
^
IndentationError: expected an indented block
>>>
Previously this would just give a ... prompt:
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if 1:
... # comment
... pass
...
>>>
|
I think it works now but i am not sure if it is an ideal solution or not. |
gvanrossum
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 have to think about this more. It seems to work but the changes look ad-hoc (and not at all what I had expected they would be when I wrote up the bug description). I need to do some deep thinking about whether this is the right place in the code to implement this behavior.
Ping me if I haven't replied in a week -- I don't want to keep you hanging forever!
|
I have a different suggestion: |
|
Thanks for your suggestions Guido. |
gvanrossum
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.
LGTM. Can one of the other reviewers double-check there's nothing amiss?
|
The 2 error cases on the issue and 2 above and otherw work for me. I presume
is correct. |
|
Thanks @isidentical for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
…espace (pythonGH-17421) https://bugs.python.org/issue38673 (cherry picked from commit 109fc27) Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
|
GH-17516 is a backport of this pull request to the 3.8 branch. |
…espace (GH-17421) https://bugs.python.org/issue38673 (cherry picked from commit 109fc27) Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
…espace (pythonGH-17421) https://bugs.python.org/issue38673 (cherry picked from commit 109fc27) Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> (cherry picked from commit 184a381) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
…espace (GH-17421) (GH-17522) https://bugs.python.org/issue38673 (cherry picked from commit 109fc27) Co-authored-by: Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
https://bugs.python.org/issue38673
Automerge-Triggered-By: @gvanrossum