Python does have a new REPL since 3.13, so that would account for the difference between versions.
But this behavior is still unexpected. My guess would be that in the case where you’re pasting code in, you’re getting both the auto-indent from the REPL and the 4 spaces you wrote in Notepad.
The specifics might depend on the environment in which you’re running things and how they handle copy/paste. My first question would be: how and where are you running your REPL? Is this behavior different if you’re pasting into a REPL running in, for example, cmd.exe versus PowerShell versus WSL?
Indeed, Python 3.13 has a brand new REPL with an autoindentation feature, which works great if you write things by hand, but does not interact well with pasted code. Fortunately, you can press F3 to enter the “paste mode” and then everything should work as expected.
From reading this related Github issue, it seems like maybe F3 may no longer be needed depending on which terminal emulator you use. From that issue:
Virtual terminal support has just been backported to 3.13, so in Windows terminals this will work now.
Only in legacy terminals F3 (paste mode) is still needed, since they do not support bracketed pasting.
Yes, using F3 (paste mode) is one solution. But I am wondering why IPython can handle this situation gracefully. Not only has auto indentation during manually coding, it also copy/paste code from notepad, and even copy/paste from a web page where lines have leading “>>>” or “…” mark.