mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
[3.11] gh-101400: Fix incorrect lineno in exception message on contin… (gh-101447)
This commit is contained in:
parent
43af2dbb54
commit
0c37ea9aba
3 changed files with 35 additions and 13 deletions
|
@ -1907,9 +1907,6 @@ class SyntaxTestCase(unittest.TestCase):
|
|||
"""
|
||||
self._check_error(source, "parameter and nonlocal", lineno=3)
|
||||
|
||||
def test_break_outside_loop(self):
|
||||
self._check_error("break", "outside loop")
|
||||
|
||||
def test_yield_outside_function(self):
|
||||
self._check_error("if 0: yield", "outside function")
|
||||
self._check_error("if 0: yield\nelse: x=1", "outside function")
|
||||
|
@ -1938,20 +1935,27 @@ class SyntaxTestCase(unittest.TestCase):
|
|||
"outside function")
|
||||
|
||||
def test_break_outside_loop(self):
|
||||
self._check_error("if 0: break", "outside loop")
|
||||
self._check_error("if 0: break\nelse: x=1", "outside loop")
|
||||
self._check_error("if 1: pass\nelse: break", "outside loop")
|
||||
self._check_error("class C:\n if 0: break", "outside loop")
|
||||
msg = "outside loop"
|
||||
self._check_error("break", msg, lineno=1)
|
||||
self._check_error("if 0: break", msg, lineno=1)
|
||||
self._check_error("if 0: break\nelse: x=1", msg, lineno=1)
|
||||
self._check_error("if 1: pass\nelse: break", msg, lineno=2)
|
||||
self._check_error("class C:\n if 0: break", msg, lineno=2)
|
||||
self._check_error("class C:\n if 1: pass\n else: break",
|
||||
"outside loop")
|
||||
msg, lineno=3)
|
||||
self._check_error("with object() as obj:\n break",
|
||||
msg, lineno=2)
|
||||
|
||||
def test_continue_outside_loop(self):
|
||||
self._check_error("if 0: continue", "not properly in loop")
|
||||
self._check_error("if 0: continue\nelse: x=1", "not properly in loop")
|
||||
self._check_error("if 1: pass\nelse: continue", "not properly in loop")
|
||||
self._check_error("class C:\n if 0: continue", "not properly in loop")
|
||||
msg = "not properly in loop"
|
||||
self._check_error("if 0: continue", msg, lineno=1)
|
||||
self._check_error("if 0: continue\nelse: x=1", msg, lineno=1)
|
||||
self._check_error("if 1: pass\nelse: continue", msg, lineno=2)
|
||||
self._check_error("class C:\n if 0: continue", msg, lineno=2)
|
||||
self._check_error("class C:\n if 1: pass\n else: continue",
|
||||
"not properly in loop")
|
||||
msg, lineno=3)
|
||||
self._check_error("with object() as obj:\n continue",
|
||||
msg, lineno=2)
|
||||
|
||||
def test_unexpected_indent(self):
|
||||
self._check_error("foo()\n bar()\n", "unexpected indent",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue