(logical_line)
r"""Each comma, semicolon or colon should be followed by whitespace.

    Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
r"""Each comma, semicolon or colon should be followed by whitespace.
r Each comma semicolon or colon should be followed by whitespace .
def missing_whitespace(logical_line):
    r"""Each comma, semicolon or colon should be followed by whitespace.

    Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
    """
    line = logical_line
    for index in range(len(line) - 1):
        char = line[index]
        if char in ',;:' and line[index + 1] not in WHITESPACE:
            before = line[:index]
            if char == ':' and before.count('[') > before.count(']') and \
                    before.rfind('{') < before.rfind('['):
                continue  # Slice syntax, no space required
            if char == ',' and line[index + 1] == ')':
                continue  # Allow tuple with only one element: (3,)
            yield index, "E231 missing whitespace after '%s'" % char
def missing_whitespace ( logical_line ) : line = logical_line for index in range ( len ( line ) - 1 ) : char = line [ index ] if char in ',;:' and line [ index + 1 ] not in WHITESPACE : before = line [ : index ] if char == ':' and before . count ( '[' ) > before . count ( ']' ) and before . rfind ( '{' ) < before . rfind ( '[' ) : continue # Slice syntax, no space required if char == ',' and line [ index + 1 ] == ')' : continue # Allow tuple with only one element: (3,) yield index , "E231 missing whitespace after '%s'" % char