Skip to content

Too Much auto indentation when a comment is in the beginning of a loop inside the REPL #125230

@SZRabinowitz

Description

@SZRabinowitz

Bug report

Bug description:

C:\Users\Admin\Downloads\python-3.13.0-embed-amd64>python
Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
>>> for i in range(5):
...     # a comment goes here
...         # now the repl indents to here
...             # then here
...                 print(i)
...
0
1
2
3
4
>>>
>>> for i in range(5):
...     print(i)
...     # now put a comment here
...     # no problem
...
0
1
2
3
4
>>>
>>> if i==4:
...     # comment here
...         #it indented to here
...             print("yes")
... else:
...     print("no")
...
yes
>>>
>>> def even_or_odd(num):
...     # comment here
...         #it indents too far
...             print("calculating...")
...             return 'eovdedn'[num % 2::2]
...
>>>
>>> for num in [0, 1, 2, 3, 4, 5, 100, 100000000, 1000000000000005]:
...     # comment here
...         #indents too far
...             print(f"{num} is {even_or_odd(num)}")
...
calculating...
0 is even
calculating...
1 is odd
calculating...
2 is even
calculating...
3 is odd
calculating...
4 is even
calculating...
5 is odd
calculating...
100 is even
calculating...
100000000 is even
calculating...
1000000000000005 is odd
>>>

I apologize if this has already been brought up, I couldn't find it.

The issue: In the new 3.13.0 REPL, if you open a loop, function, if statement, or anything that requires indentation, and then start the next line with a comment, it indents extra spaces.

I have a few examples above.

My PC: Windows 11
python version: 3.13.0

Steps to reproduce:

  1. Download an install python 3.13.0 and open the python repl.
  2. start a for loop and press enter : E.G. for i in range(5):
  3. start the next line with a comment and press enter: E.G. # My comment here
  4. it will indent another level which is too far

Thank you so much everyone for python development and I hope I explained the issue clearly.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions