diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2022-01-25 22:12:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-25 22:12:14 (GMT) |
commit | a0efc0c1960e2c49e0092694d98395555270914c (patch) | |
tree | beee479f9d645494a6a1d216d7f48932010d67a9 /Lib/test/test_syntax.py | |
parent | b1cb8430504931f7854eac5d32cba74770078a4e (diff) | |
download | cpython-a0efc0c1960e2c49e0092694d98395555270914c.zip cpython-a0efc0c1960e2c49e0092694d98395555270914c.tar.gz cpython-a0efc0c1960e2c49e0092694d98395555270914c.tar.bz2 |
bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 968d348..a6ff319 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -1613,6 +1613,36 @@ pass except SyntaxError: self.fail("Empty line after a line continuation character is valid.") + # See issue-46091 + s1 = r"""\ +def fib(n): + \ +'''Print a Fibonacci series up to n.''' + \ +a, b = 0, 1 +""" + s2 = r"""\ +def fib(n): + '''Print a Fibonacci series up to n.''' + a, b = 0, 1 +""" + try: + self.assertEqual(compile(s1, '<string>', 'exec'), compile(s2, '<string>', 'exec')) + except SyntaxError: + self.fail("Indented statement over multiple lines is valid") + + def test_continuation_bad_indentation(self): + # Check that code that breaks indentation across multiple lines raises a syntax error + + code = r"""\ +if x: + y = 1 + \ + foo = 1 + """ + + self.assertRaises(IndentationError, exec, code) + @support.cpython_only def test_nested_named_except_blocks(self): code = "" |