18531853 Traceback (most recent call last):
18541854 SyntaxError: positional patterns follow keyword patterns
18551855
1856- Non-matching 'elif'/'else' statements:
1857-
1858- >>> if a == b:
1859- ... ...
1860- ... elif a == c:
1861- Traceback (most recent call last):
1862- SyntaxError: 'elif' must match an if-statement here
1863-
1864- >>> if x == y:
1865- ... ...
1866- ... else:
1867- Traceback (most recent call last):
1868- SyntaxError: 'else' must match a valid statement here
1869-
1870- >>> elif m == n:
1871- Traceback (most recent call last):
1872- SyntaxError: 'elif' must match an if-statement here
1873-
1874- >>> else:
1875- Traceback (most recent call last):
1876- SyntaxError: 'else' must match a valid statement here
1877-
18781856Uses of the star operator which should fail:
18791857
18801858A[:*b]
@@ -2167,8 +2145,8 @@ def _check_error(self, code, errtext,
21672145 lineno = None , offset = None , end_lineno = None , end_offset = None ):
21682146 """Check that compiling code raises SyntaxError with errtext.
21692147
2170- errtext is a regular expression that must be present in the
2171- test of the exception raised. If subclass is specified, it
2148+ errtest is a regular expression that must be present in the
2149+ test of the exception raised. If subclass is specified it
21722150 is the expected subclass of SyntaxError (e.g. IndentationError).
21732151 """
21742152 try :
@@ -2192,22 +2170,6 @@ def _check_error(self, code, errtext,
21922170 else :
21932171 self .fail ("compile() did not raise SyntaxError" )
21942172
2195- def _check_noerror (self , code ,
2196- errtext = "compile() raised unexpected SyntaxError" ,
2197- filename = "<testcase>" , mode = "exec" , subclass = None ):
2198- """Check that compiling code does not raise a SyntaxError.
2199-
2200- errtext is the message passed to self.fail if there is
2201- a SyntaxError. If the subclass parameter is specified,
2202- it is the subclass of SyntaxError (e.g. IndentationError)
2203- that the raised error is checked against.
2204- """
2205- try :
2206- compile (code , filename , mode )
2207- except SyntaxError as err :
2208- if (not subclass ) or isinstance (err , subclass ):
2209- self .fail (errtext )
2210-
22112173 def test_expression_with_assignment (self ):
22122174 self ._check_error (
22132175 "print(end1 + end2 = ' ')" ,
@@ -2609,25 +2571,6 @@ def test_syntax_error_on_deeply_nested_blocks(self):
26092571"""
26102572 self ._check_error (source , "too many statically nested blocks" )
26112573
2612- def test_syntax_error_non_matching_elif_else_statements (self ):
2613- # Check bpo-45759: 'elif' statements that doesn't match an
2614- # if-statement or 'else' statements that doesn't match any
2615- # valid else-able statement (e.g. 'while')
2616- self ._check_error (
2617- "elif m == n:\n ..." ,
2618- "'elif' must match an if-statement here" )
2619- self ._check_error (
2620- "else:\n ..." ,
2621- "'else' must match a valid statement here" )
2622- self ._check_noerror ("if a == b:\n ...\n elif a == c:\n ..." )
2623- self ._check_noerror ("if x == y:\n ...\n else:\n ..." )
2624- self ._check_error (
2625- "else = 123" ,
2626- "invalid syntax" )
2627- self ._check_error (
2628- "elif 55 = 123" ,
2629- "cannot assign to literal here" )
2630-
26312574 @support .cpython_only
26322575 def test_error_on_parser_stack_overflow (self ):
26332576 source = "-" * 100000 + "4"
0 commit comments