@@ -1150,6 +1150,37 @@ def comparison_type(logical_line, noqa):
11501150 yield match .start (), "E721 do not compare types, use 'isinstance()'"
11511151
11521152
1153+ def ambiguous_identifier (logical_line , tokens ):
1154+ r"""Never use the characters 'l', 'O', or 'I' as variable names.
1155+
1156+ In some fonts, these characters are indistinguishable from the numerals
1157+ one and zero. When tempted to use 'l', use 'L' instead.
1158+
1159+ Okay: L = 0
1160+ E741: l = 0
1161+ """
1162+ idents_to_avoid = ('l' , 'O' , 'I' )
1163+ prev_type , prev_text , prev_start , prev_end , __ = tokens [0 ]
1164+ for token_type , text , start , end , line in tokens [1 :]:
1165+ ident = pos = None
1166+ # identifiers on the lhs of an assignment operator
1167+ if token_type == tokenize .OP and '=' in text :
1168+ if prev_text in idents_to_avoid :
1169+ ident = prev_text
1170+ pos = prev_start
1171+ # identifiers after 'as'
1172+ if prev_text == 'as' :
1173+ if text in idents_to_avoid :
1174+ ident = text
1175+ pos = start
1176+ if ident :
1177+ yield pos , "E741 ambiguous variable name '%s'" % ident
1178+ prev_type = token_type
1179+ prev_text = text
1180+ prev_start = start
1181+ prev_end = end
1182+
1183+
11531184def python_3000_has_key (logical_line , noqa ):
11541185 r"""The {}.has_key() method is removed in Python 3: use the 'in' operator.
11551186
0 commit comments