@@ -444,27 +444,29 @@ def is_a_slice(line, space_pos):
444444 parentheses_brackets_braces = list ()
445445 for i in range (space_pos ):
446446 c = line [i ]
447- if c in ' [({' :
447+ if c in " [({" :
448448 # add it to the stack
449449 parentheses_brackets_braces .append ((c , i ))
450- elif c in ' ])}' :
450+ elif c in " ])}" :
451451 # unstack last item and check consistency
452452 last_opened = parentheses_brackets_braces .pop ()[0 ]
453- expected_close = {'{' : '}' , '(' : ')' , '[' : ']' }[last_opened ]
453+ expected_close = {"{" : "}" , "(" : ")" , "[" : "]" }[last_opened ]
454454 if c != expected_close : # invalid Python code
455455 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+ )
458460
459461 is_lambda_expr = False
460462 if is_within_brackets :
461463 # check for a lambda expression nested in brackets
462464 if space_pos > 6 :
463465 last_opened = parentheses_brackets_braces [- 1 ]
464466 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
466468
467- return ( is_within_brackets and not is_lambda_expr )
469+ return is_within_brackets and not is_lambda_expr
468470
469471 line = logical_line
470472 for match in EXTRANEOUS_WHITESPACE_REGEX .finditer (line ):
@@ -474,12 +476,15 @@ def is_a_slice(line, space_pos):
474476 if text == char + ' ' :
475477 # assert char in '([{'
476478 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 ',;:'
480484 yield found , "%s whitespace before '%s'" % (code , char )
481485
482486
487+
483488@register_check
484489def whitespace_around_keywords (logical_line ):
485490 r"""Avoid extraneous whitespace around keywords.
0 commit comments