mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
[3.10] bpo-46091: Correctly calculate indentation levels for whitespace lines with continuation characters (GH-30130). (GH-30898)
(cherry picked from commit a0efc0c196
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
4a57fa296b
commit
3fc8b74ace
5 changed files with 67 additions and 16 deletions
|
@ -1463,6 +1463,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 = ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue