diff options
-rw-r--r-- | docs/intro.rst | 4 | ||||
-rwxr-xr-x | pycodestyle.py | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/docs/intro.rst b/docs/intro.rst index bfa6786..11b0e0c 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -360,6 +360,10 @@ This is the current list of error and warning codes: +------------+----------------------------------------------------------------------+ | E741 | do not use variables named 'l', 'O', or 'I' | +------------+----------------------------------------------------------------------+ +| E742 | do not define classes named 'l', 'O', or 'I' | ++------------+----------------------------------------------------------------------+ +| E743 | do not define functions named 'l', 'O', or 'I' | ++------------+----------------------------------------------------------------------+ +------------+----------------------------------------------------------------------+ | **E9** | *Runtime* | +------------+----------------------------------------------------------------------+ diff --git a/pycodestyle.py b/pycodestyle.py index f92d860..11cb879 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1163,13 +1163,18 @@ def ambiguous_identifier(logical_line, tokens): E741: O = 123 E741: I = 42 - Variables can be bound in other contexts, so identifiers appearing after - the 'as' keyword are also reported: + Variables can be bound in several other contexts, including class and + function definitions, 'global' and 'nonlocal' statements, exception + handlers, and 'with' statements. Okay: except AttributeError as o: Okay: with lock as L: E741: except AttributeError as O: E741: with lock as l: + E741: global I + E741: nonlocal l + E742: class I(object): + E743: def l(x): """ idents_to_avoid = ('l', 'O', 'I') prev_type, prev_text, prev_start, prev_end, __ = tokens[0] @@ -1185,6 +1190,12 @@ def ambiguous_identifier(logical_line, tokens): if text in idents_to_avoid: ident = text pos = start + if prev_text == 'class': + if text in idents_to_avoid: + yield start, "E742 ambiguous class definition '%s'" % text + if prev_text == 'def': + if text in idents_to_avoid: + yield start, "E743 ambiguous function definition '%s'" % text if ident: yield pos, "E741 ambiguous variable name '%s'" % ident prev_type = token_type |