Skip to content

Conversation

@isidentical
Copy link
Member

@isidentical isidentical commented Nov 30, 2019

@terryjreedy
Copy link
Member

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.

Copy link
Member

@gvanrossum gvanrossum left a 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...

@isidentical
Copy link
Member Author

Thanks for suggestions @gvanrossum, current version fixed accumulation bug.

if (tok->nextprompt != NULL)
tok->prompt = tok->nextprompt;
if (tok->nextprompt != NULL) {
if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t'))
Copy link
Member

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

if (tok->nextprompt != NULL) {
if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t'))
tok->nextprompt = NULL;
else
Copy link
Member

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

if (tok->nextprompt != NULL)
tok->prompt = tok->nextprompt;
if (tok->nextprompt != NULL) {
if (newtok != NULL && (*newtok == '#' || *newtok == ' ' || *newtok == '\t'))
Copy link
Member

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).

Copy link
Member Author

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.

@pablogsal
Copy link
Member

Left some comment regarding the code itself, I didn't check the solution itself yet.

@gvanrossum
Copy link
Member

(I am working through a backlog, I should pay attention to reviews and other tasks that have been waiting longer first.)

Copy link
Member

@gvanrossum gvanrossum left a 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
... 
>>> 

@isidentical
Copy link
Member Author

I think it works now but i am not sure if it is an ideal solution or not.

Copy link
Member

@gvanrossum gvanrossum left a 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!

@gvanrossum
Copy link
Member

I have a different suggestion:

--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -1148,6 +1148,12 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
             if (col == 0 && c == '\n' && tok->prompt != NULL) {
                 blankline = 0; /* Let it through */
             }
+            else if (tok->prompt != NULL && tok->lineno == 1) {
+                /* In interactive mode, if the first line contains
+                   only spaces and a comment, let it through. */
+                blankline = 0;
+                col = altcol = 0;
+            }
             else {
                 blankline = 1; /* Ignore completely */

@isidentical
Copy link
Member Author

Thanks for your suggestions Guido.

Copy link
Member

@gvanrossum gvanrossum left a 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?

@terryjreedy
Copy link
Member

The 2 error cases on the issue and 2 above and otherw work for me. I presume

if 1:
... # k
... # k
... a = 2
... )
File "", line 5
SyntaxError: unmatched ')'

is correct.

@miss-islington
Copy link
Contributor

Thanks @isidentical for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 9, 2019
…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>
@bedevere-bot
Copy link

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

miss-islington added a commit that referenced this pull request Dec 9, 2019
…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>
miss-islington added a commit to miss-islington/cpython that referenced this pull request Dec 9, 2019
…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>
ned-deily pushed a commit that referenced this pull request Dec 9, 2019
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants