@@ -493,6 +493,17 @@ def whitespace_around_keywords(logical_line):
493
493
yield match .start (2 ), "E271 multiple spaces after keyword"
494
494
495
495
496
+ if sys .version_info < (3 , 10 ):
497
+ from itertools import tee
498
+
499
+ def pairwise (iterable ):
500
+ a , b = tee (iterable )
501
+ next (b , None )
502
+ return zip (a , b )
503
+ else :
504
+ from itertools import pairwise
505
+
506
+
496
507
@register_check
497
508
def missing_whitespace_after_keyword (logical_line , tokens ):
498
509
r"""Keywords should be followed by whitespace.
@@ -502,7 +513,7 @@ def missing_whitespace_after_keyword(logical_line, tokens):
502
513
E275: from importable.module import(bar, baz)
503
514
E275: if(foo): bar
504
515
"""
505
- for tok0 , tok1 in zip (tokens , tokens [ 1 :] ):
516
+ for tok0 , tok1 in pairwise (tokens ):
506
517
# This must exclude the True/False/None singletons, which can
507
518
# appear e.g. as "if x is None:", and async/await, which were
508
519
# valid identifier names in old Python versions.
@@ -512,7 +523,7 @@ def missing_whitespace_after_keyword(logical_line, tokens):
512
523
tok0 .string not in SINGLETONS and
513
524
not (tok0 .string == 'except' and tok1 .string == '*' ) and
514
525
not (tok0 .string == 'yield' and tok1 .string == ')' ) and
515
- tok1 .string not in ': \n ' ):
526
+ ( tok1 .string and tok1 . string != ':' and tok1 . string != ' \n ') ):
516
527
yield tok0 .end , "E275 missing whitespace after keyword"
517
528
518
529
0 commit comments