Skip to content

fix indentation error with starting comment - #14721

Merged
Carreau merged 2 commits into
ipython:mainfrom
maurerle:fix_comment_start
Feb 5, 2025
Merged

Carreau merged 2 commits into
ipython:mainfrom
maurerle:fix_comment_start

Conversation

@maurerle

@maurerle maurerle commented Feb 4, 2025 •

Copy link
Copy Markdown
Contributor

closes #14242

This happens when executing something like:

    # comment
print("hello")

for i in range(7):
    print(i)
print("goodbye")

for some reason this is treated wrongly.
We have to explicitly check for starting # here.

Checking for multiline comments or single line strings with ' or " is not needed as cpython does not render such input valid as well.

I also experimented with some regex like this: ^[ \t]+(?=[^'"#\t ]) to check for existance of #, ' or ", though I don't think this is helpful here.

The issue is especially weird, as the typical error message is

  Cell In[1], line 5
    print("goodbye")
    ^
IndentationError: expected an indented block after 'for' statement on line 4

while the error is in the first line..

@maurerle

maurerle commented Feb 4, 2025

Copy link
Copy Markdown
Contributor Author

I don't understand why darker does not like my formatting which is the same as the rest of the file..

@Carreau

Carreau commented Feb 5, 2025

Copy link
Copy Markdown
Member

I don't understand why darker does not like my formatting which is the same as the rest of the file..

Don't worry about that.

@Carreau

Carreau commented Feb 5, 2025

Copy link
Copy Markdown
Member

Thanks !

@Carreau
Carreau merged commit 0a2e90f into ipython:main Feb 5, 2025
@Carreau Carreau added this to the 9.0 milestone Feb 5, 2025
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.

Inconsistent raising of IndentationError on for and if blocks after mismatching indented comment

2 participants