Skip to content

Commit fdf3e6a

Browse files
committed
Report E742 and E743 for badly named functions and classes
1 parent 017d3b5 commit fdf3e6a

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

docs/intro.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ This is the current list of error and warning codes:
360360
+------------+----------------------------------------------------------------------+
361361
| E741 | do not use variables named 'l', 'O', or 'I' |
362362
+------------+----------------------------------------------------------------------+
363+
| E742 | do not define classes named 'l', 'O', or 'I' |
364+
+------------+----------------------------------------------------------------------+
365+
| E743 | do not define functions named 'l', 'O', or 'I' |
366+
+------------+----------------------------------------------------------------------+
363367
+------------+----------------------------------------------------------------------+
364368
| **E9** | *Runtime* |
365369
+------------+----------------------------------------------------------------------+

pycodestyle.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,18 @@ def ambiguous_identifier(logical_line, tokens):
11631163
E741: O = 123
11641164
E741: I = 42
11651165
1166-
Variables can be bound in other contexts, so identifiers appearing after
1167-
the 'as' keyword are also reported:
1166+
Variables can be bound in several other contexts, including class and
1167+
function definitions, 'global' and 'nonlocal' statements, exception
1168+
handlers, and 'with' statements.
11681169
11691170
Okay: except AttributeError as o:
11701171
Okay: with lock as L:
11711172
E741: except AttributeError as O:
11721173
E741: with lock as l:
1174+
E741: global I
1175+
E741: nonlocal l
1176+
E742: class I(object):
1177+
E743: def l(x):
11731178
"""
11741179
idents_to_avoid = ('l', 'O', 'I')
11751180
prev_type, prev_text, prev_start, prev_end, __ = tokens[0]
@@ -1185,6 +1190,12 @@ def ambiguous_identifier(logical_line, tokens):
11851190
if text in idents_to_avoid:
11861191
ident = text
11871192
pos = start
1193+
if prev_text == 'class':
1194+
if text in idents_to_avoid:
1195+
yield start, "E742 ambiguous class definition '%s'" % text
1196+
if prev_text == 'def':
1197+
if text in idents_to_avoid:
1198+
yield start, "E743 ambiguous function definition '%s'" % text
11881199
if ident:
11891200
yield pos, "E741 ambiguous variable name '%s'" % ident
11901201
prev_type = token_type

0 commit comments

Comments
 (0)