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.

classification
Title: Improve syntax error for indentation errors
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, aroberge, pablogsal
Priority: normal Keywords: patch

Created on 2021-04-16 00:26 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25431 merged pablogsal, 2021-04-16 00:27
Messages (2)
msg391160 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-16 00:26
The current indentation error is quite simplistic and it does not include the context of the statement that was associated with the indented block and where it was:

>>> def foo():
...     if lel:
...     x = 2
  File "<stdin>", line 3
    x = 2
    ^
IndentationError: expected an indented block

we can improve the error by adding some context:

>>> def foo():
...    if lel:
...    x = 2
  File "<stdin>", line 3
    x = 2
    ^
IndentationError: expected an indented block after if statement in line 2
msg391523 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-04-21 14:28
New changeset 56c95dfe271b1242bdc8163d4677e311552c00cb by Pablo Galindo in branch 'master':
bpo-43859: Improve the error message for IndentationError exceptions (GH-25431)
https://github.com/python/cpython/commit/56c95dfe271b1242bdc8163d4677e311552c00cb
History
Date User Action Args
2022-04-11 14:59:44adminsetgithub: 88025
2021-04-21 14:32:46pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-21 14:28:41pablogsalsetmessages: + msg391523
2021-04-16 10:40:03arobergesetnosy: + aroberge
2021-04-16 00:27:28pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24162
2021-04-16 00:26:09pablogsalcreate