summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Miller <mike@mtmxr.com>2016-06-03 10:03:24 -0700
committerMike Miller <mike@mtmxr.com>2016-06-03 10:03:24 -0700
commitfdf3e6a2655c8ddd465781e1c2693886a8aa762f (patch)
treecfeff4a8ac46539b337ed8599c8968ce70a29822
parent017d3b5da0c37bd48df3778752bfa98b4eed6d5e (diff)
downloadpep8-fdf3e6a2655c8ddd465781e1c2693886a8aa762f.tar.gz
Report E742 and E743 for badly named functions and classes
-rw-r--r--docs/intro.rst4
-rwxr-xr-xpycodestyle.py15
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