bpo-43859: Improve the error message for IndentationError exceptions (GH-25431)
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index d93b0f16..e0e8191 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -179,7 +179,7 @@ def ckmsg(src, msg, exception=SyntaxError):
# should not apply to subclasses, see issue #31161
s = '''if True:\nprint "No indent"'''
- ckmsg(s, "expected an indented block", IndentationError)
+ ckmsg(s, "expected an indented block after 'if' statement on line 1", IndentationError)
s = '''if True:\n print()\n\texec "mixed tabs and spaces"'''
ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError)
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 5f622b0..dc81964 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -926,6 +926,138 @@
Traceback (most recent call last):
SyntaxError: invalid syntax
+Specialized indentation errors:
+
+ >>> while condition:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'while' statement on line 1
+
+ >>> for x in range(10):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'for' statement on line 1
+
+ >>> for x in range(10):
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 3
+
+ >>> async for x in range(10):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'for' statement on line 1
+
+ >>> async for x in range(10):
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 3
+
+ >>> if something:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'if' statement on line 1
+
+ >>> if something:
+ ... pass
+ ... elif something_else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'elif' statement on line 3
+
+ >>> if something:
+ ... pass
+ ... elif something_else:
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 5
+
+ >>> try:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'try' statement on line 1
+
+ >>> try:
+ ... something()
+ ... except A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'except' statement on line 3
+
+ >>> try:
+ ... something()
+ ... except A:
+ ... pass
+ ... finally:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'finally' statement on line 5
+
+ >>> with A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> with A as a, B as b:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> with (A as a, B as b):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with A as a, B as b:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with (A as a, B as b):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> def foo(x, /, y, *, z=2):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after function definition on line 1
+
+ >>> class Blech(A):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after class definition on line 1
+
+ >>> match something:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'match' statement on line 1
+
+ >>> match something:
+ ... case []:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'case' statement on line 2
+
+ >>> match something:
+ ... case []:
+ ... ...
+ ... case {}:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'case' statement on line 4
+
Make sure that the old "raise X, Y[, Z]" form is gone:
>>> raise X, Y
Traceback (most recent call last):