def whitespace_before_comment(logical_line, tokens):
 prev_end = (0, 0)
 for (token_type, text, start, end, line) in tokens:
  if (token_type == tokenize.COMMENT):
   inline_comment = line[:start[1]].strip()
   if inline_comment:
    if ((prev_end[0] == start[0]) and (start[1] < (prev_end[1] + 2))):
     (yield (prev_end, 'E261 at least two spaces before inline comment'))
   (symbol, sp, comment) = text.partition(' ')
   bad_prefix = (symbol not in ('#', '#:'))
   if inline_comment:
    if (bad_prefix or comment[:1].isspace()):
     (yield (start, "E262 inline comment should start with '# '"))
   elif bad_prefix:
    if (text.rstrip('#') and ((start[0] > 1) or (symbol[1] != '!'))):
     (yield (start, "E265 block comment should start with '# '"))
  elif (token_type != tokenize.NL):
   prev_end = end

def whitespace_before_comment ( logical_line , tokens ) : prev_end = ( 0 , 0 ) for ( token_type , text , start , end , line ) in tokens : if ( token_type == tokenize . COMMENT ) : inline_comment = line [ : start [ 1 ] ] . strip ( ) if inline_comment : if ( ( prev_end [ 0 ] == start [ 0 ] ) and ( start [ 1 ] < ( prev_end [ 1 ] + 2 ) ) ) : ( yield ( prev_end , 'E261 at least two spaces before inline comment' ) ) ( symbol , sp , comment ) = text . partition ( ' ' ) bad_prefix = ( symbol not in ( '#' , '#:' ) ) if inline_comment : if ( bad_prefix or comment [ : 1 ] . isspace ( ) ) : ( yield ( start , "E262 inline comment should start with '# '" ) ) elif bad_prefix : if ( text . rstrip ( '#' ) and ( ( start [ 0 ] > 1 ) or ( symbol [ 1 ] != '!' ) ) ) : ( yield ( start , "E265 block comment should start with '# '" ) ) elif ( token_type != tokenize . NL ) : prev_end = end
separate inline comments by at least two spaces .