Skip to content
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

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

Closed
SZRabinowitz opened this issue Oct 9, 2024 · 3 comments
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@SZRabinowitz
Copy link

SZRabinowitz commented Oct 9, 2024

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

@SZRabinowitz SZRabinowitz added the type-bug An unexpected behavior, bug, or error label Oct 9, 2024
@SZRabinowitz
Copy link
Author

I also tested this in WSL2 and had the same issue:

┌──(shlomo㉿LAPTOP-0MT4TU0L)-[/mnt/c/Users/Admin/Downloads]
└─$ uv python install 3.13.0
Searching for Python versions matching: Python 3.13.0
Installed Python 3.13.0rc2 in 2.94s
 + cpython-3.13.0rc2-linux-x86_64-gnu

┌──(shlomo㉿LAPTOP-0MT4TU0L)-[/mnt/c/Users/Admin/Downloads]
└─$ uv run --python 3.13.0 -- python
Python 3.13.0rc2 (main, Sep  9 2024, 22:13:26) [Clang 18.1.8 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> for i in range(5):
...     # comment here
...         print(i)
...
0
1
2
3
4
>>>

So it is more than likely a cross platform issue, but not necessarily

@y5c4l3
Copy link
Contributor

y5c4l3 commented Oct 9, 2024

#122237

@SZRabinowitz
Copy link
Author

Thank you for pointing out the duplicate @y5c4l3.

I am closing this issue as duplicate.

@hugovk hugovk added the topic-repl Related to the interactive shell label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants