@@ -444,27 +444,29 @@ def is_a_slice(line, space_pos):
444
444
parentheses_brackets_braces = list ()
445
445
for i in range (space_pos ):
446
446
c = line [i ]
447
- if c in ' [({' :
447
+ if c in " [({" :
448
448
# add it to the stack
449
449
parentheses_brackets_braces .append ((c , i ))
450
- elif c in ' ])}' :
450
+ elif c in " ])}" :
451
451
# unstack last item and check consistency
452
452
last_opened = parentheses_brackets_braces .pop ()[0 ]
453
- expected_close = {'{' : '}' , '(' : ')' , '[' : ']' }[last_opened ]
453
+ expected_close = {"{" : "}" , "(" : ")" , "[" : "]" }[last_opened ]
454
454
if c != expected_close : # invalid Python code
455
455
return False
456
- is_within_brackets = (len (parentheses_brackets_braces ) > 0 and
457
- parentheses_brackets_braces [- 1 ][0 ] == '[' )
456
+ is_within_brackets = (
457
+ len (parentheses_brackets_braces ) > 0
458
+ and parentheses_brackets_braces [- 1 ][0 ] == "["
459
+ )
458
460
459
461
is_lambda_expr = False
460
462
if is_within_brackets :
461
463
# check for a lambda expression nested in brackets
462
464
if space_pos > 6 :
463
465
last_opened = parentheses_brackets_braces [- 1 ]
464
466
between_bracket_colon = line [last_opened [1 ] + 1 : space_pos ]
465
- is_lambda_expr = ' lambda' in between_bracket_colon
467
+ is_lambda_expr = " lambda" in between_bracket_colon
466
468
467
- return ( is_within_brackets and not is_lambda_expr )
469
+ return is_within_brackets and not is_lambda_expr
468
470
469
471
line = logical_line
470
472
for match in EXTRANEOUS_WHITESPACE_REGEX .finditer (line ):
@@ -474,12 +476,15 @@ def is_a_slice(line, space_pos):
474
476
if text == char + ' ' :
475
477
# assert char in '([{'
476
478
yield found + 1 , "E201 whitespace after '%s'" % char
477
- elif (line [found - 1 ] != ',' and
478
- not (char == ':' and is_a_slice (line , found ))):
479
- code = ('E202' if char in '}])' else 'E203' ) # if char in ',;:'
479
+ elif (
480
+ line [found - 1 ] != ','
481
+ and not (char == ':' and is_a_slice (line , found ))
482
+ ):
483
+ code = "E202" if char in "}])" else "E203" # if char in ',;:'
480
484
yield found , "%s whitespace before '%s'" % (code , char )
481
485
482
486
487
+
483
488
@register_check
484
489
def whitespace_around_keywords (logical_line ):
485
490
r"""Avoid extraneous whitespace around keywords.
0 commit comments