@@ -480,20 +480,25 @@ def whitespace_around_keywords(logical_line):
480480
481481
482482@register_check
483- def missing_whitespace_after_import_keyword (logical_line ):
484- r"""Multiple imports in form from x import (a, b, c) should have
485- space between import statement and parenthesised name list.
483+ def missing_whitespace_after_keyword (logical_line , tokens ):
484+ r"""Keywords should be followed by whitespace.
486485
487486 Okay: from foo import (bar, baz)
488487 E275: from foo import(bar, baz)
489488 E275: from importable.module import(bar, baz)
489+ E275: if(foo): bar
490+ E275: 1 and(2 or 3)
490491 """
491- line = logical_line
492- indicator = ' import('
493- if line .startswith ('from ' ):
494- found = line .find (indicator )
495- if - 1 < found :
496- pos = found + len (indicator ) - 1
492+ for tok0 , tok1 in zip (tokens , tokens [1 :]):
493+ # This must exclude the True/False/None singletons, which can appear
494+ # e.g. as "if x is None:", and async/await, which were valid identifier
495+ # names in old Python versions.
496+ if (tok0 .end == tok1 .start and
497+ keyword .iskeyword (tok0 .string ) and
498+ tok0 .string not in SINGLETONS and
499+ tok0 .string not in ('async' , 'await' ) and
500+ tok1 .string not in ':\n ' ):
501+ line , pos = tok0 .end
497502 yield pos , "E275 missing whitespace after keyword"
498503
499504
0 commit comments