This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: IndendationError from multi-line indented statements
Type: Stage: resolved
Components: Parser Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, lys.nikolaou, pablogsal, ucodery
Priority: normal Keywords: patch

Created on 2021-12-15 23:06 by ucodery, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit ucodery, 2021-12-15 23:06 example program where every indented line also uses '\'
Pull Requests
URL Status Linked Edit
PR 30130 merged pablogsal, 2021-12-16 00:25
PR 30898 merged pablogsal, 2022-01-25 22:13
PR 30899 closed pablogsal, 2022-01-25 22:36
Messages (7)
msg408651 - (view) Author: Jeremy (ucodery) * Date: 2021-12-15 23:06
At some point in 3.9 Python appears to have stopped accepting source that starts with an indent, then a '\', then the indented statement. From the lexical analysis [1] "Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation."

Running the attached program under 3.8.12 I get:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

But running under 3.10.0 I get:
  File "/Users/jeremyp/tmp/", line 3
    """Print a Fibonacci series up to n."""
IndentationError: expected an indented block after function definition on line 1

Running under 3.9.9 also gives an IndentationError, both with and without -X oldparser. So this doesn't seem directly related to the new parser, but seems likely it is fall out from the general grammar restructuring.

IMHO it isn't a particularly nice feature for the language to have. Especially since not all lines like '    \' behave the same. But it was there and documented for many years, so should probably be put back. Does a core developer agree? That the implementation is not following the spec?

msg408654 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-15 23:27
This is a side effect on the fix in:
msg408656 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-15 23:35
Unfortunately I am not sure if this is going to be easier to retrofit for the reasons exposed in the issue. I will try to take a look, but if you have some cycles to spare, a PR would be welcomed.
msg408661 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-12-16 00:25
nevermind, I am convinced is a bug. I filed a PR for it
msg408663 - (view) Author: Jeremy (ucodery) * Date: 2021-12-16 00:40
Wow, this was a fast turnaround! I was going to spin some cycles on this, but would have not seen the solution in 50m.
msg411678 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-25 22:12
New changeset a0efc0c1960e2c49e0092694d98395555270914c by Pablo Galindo Salgado in branch 'main':
bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130)
msg411680 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-25 22:34
New changeset 3fc8b74ace033a17346a992f661928ba619e61e8 by Pablo Galindo Salgado in branch '3.10':
[3.10] bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130). (GH-30898)
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90249
2022-01-25 22:38:52pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-25 22:36:05pablogsalsetpull_requests: + pull_request29078
2022-01-25 22:34:06pablogsalsetmessages: + msg411680
2022-01-25 22:13:57pablogsalsetstage: patch review
pull_requests: + pull_request29077
2022-01-25 22:12:18pablogsalsetmessages: + msg411678
2021-12-16 00:47:31pablogsalsetmessages: - msg408657
2021-12-16 00:40:16ucoderysetmessages: + msg408663
2021-12-16 00:25:18pablogsalsetmessages: + msg408661
stage: patch review -> (no value)
2021-12-16 00:25:05pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28349
2021-12-15 23:38:17pablogsalsetnosy: + gvanrossum
messages: + msg408657
2021-12-15 23:35:16pablogsalsetmessages: + msg408656
2021-12-15 23:27:48pablogsalsetmessages: + msg408654
2021-12-15 23:06:30ucoderycreate