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: IndentationError for unexpected indent
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: loewis Nosy List: georg.brandl, loewis, rcmiller
Priority: normal Keywords: patch

Created on 2006-04-24 23:12 by rcmiller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch_indent_error rcmiller, 2006-04-24 23:12 patch for IndendationError
Messages (3)
msg50106 - (view) Author: Roger Miller (rcmiller) Date: 2006-04-24 23:12
This patch raises an IndentationError rather than a
generic "invalid syntax" error for unexpected
indentation.  Code to do this was already in
pythonrun.c:err_input() but was not being reached due
to a failure to pass the INDENT token in the perrdetail
structure.  The patch also adds tests for the 3 kinds
of indentation errors (unexpected indent, no indent
where required, invalid outdent level) to test_syntax.py .
msg50107 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-04-30 11:20
Logged In: YES 
user_id=849994

Martin, do we want to change this? I myself have always
wondered what IndentationError was for if it was not raised
in these cases.
msg50108 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-05-04 05:51
Logged In: YES 
user_id=21627

IndentationError is already raised for bad indentation, e.g.
for

"def f():\nreturn"

or

if 1:\nfoo()" (which is the test_no_indent)

However, the patch is right in filling the token in this
case, also; I accepted it as r45897. As it changes the
exceptio behaviour, I don't think it should be backported.
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43273
2006-04-24 23:12:04rcmillercreate