1853
1853
Traceback (most recent call last):
1854
1854
SyntaxError: positional patterns follow keyword patterns
1855
1855
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
-
1878
1856
Uses of the star operator which should fail:
1879
1857
1880
1858
A[:*b]
@@ -2167,8 +2145,8 @@ def _check_error(self, code, errtext,
2167
2145
lineno = None , offset = None , end_lineno = None , end_offset = None ):
2168
2146
"""Check that compiling code raises SyntaxError with errtext.
2169
2147
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
2172
2150
is the expected subclass of SyntaxError (e.g. IndentationError).
2173
2151
"""
2174
2152
try :
@@ -2192,22 +2170,6 @@ def _check_error(self, code, errtext,
2192
2170
else :
2193
2171
self .fail ("compile() did not raise SyntaxError" )
2194
2172
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
-
2211
2173
def test_expression_with_assignment (self ):
2212
2174
self ._check_error (
2213
2175
"print(end1 + end2 = ' ')" ,
@@ -2609,25 +2571,6 @@ def test_syntax_error_on_deeply_nested_blocks(self):
2609
2571
"""
2610
2572
self ._check_error (source , "too many statically nested blocks" )
2611
2573
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
-
2631
2574
@support .cpython_only
2632
2575
def test_error_on_parser_stack_overflow (self ):
2633
2576
source = "-" * 100000 + "4"
0 commit comments