aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-04-21 15:28:21 +0100
committerGitHub <noreply@github.com>2021-04-21 15:28:21 +0100
commit56c95dfe271b1242bdc8163d4677e311552c00cb (patch)
tree05ece745311032fba0f63e2cbd9a69c54b7e3ada /Lib/test/test_syntax.py
parentb0544ba77cf86074fb1adde00558c67ca75eeea1 (diff)
downloadcpython-56c95dfe271b1242bdc8163d4677e311552c00cb.tar.gz
cpython-56c95dfe271b1242bdc8163d4677e311552c00cb.zip
bpo-43859: Improve the error message for IndentationError exceptions (GH-25431)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py132
1 files changed, 132 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 5f622b092f9..dc81964830a 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -926,6 +926,138 @@ Incomplete dictionary literals
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):