summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
authormemeplex <carlosjosepita@gmail.com>2016-06-28 21:16:36 -0300
committermemeplex <carlosjosepita@gmail.com>2016-06-28 21:16:36 -0300
commit36e3400f65268d1ee76845a74aae5b0112182ef8 (patch)
treefce1917ce6a2adeb6663feeb4e9157d152318a25 /pycodestyle.py
parent4438622d0b62df53a1999301d1bdc9fa119ae763 (diff)
downloadpep8-36e3400f65268d1ee76845a74aae5b0112182ef8.tar.gz
Special case for nested functions an classes (fixes #28)
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index a5f5534..a043f04 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -238,7 +238,8 @@ def maximum_line_length(physical_line, max_line_length, multiline, noqa):
def blank_lines(logical_line, blank_lines, indent_level, line_number,
blank_before, previous_logical,
- previous_unindented_logical_line, previous_indent_level):
+ previous_unindented_logical_line, previous_indent_level,
+ lines):
r"""Separate top-level function and class definitions with two blank lines.
Method definitions inside a class are separated by a single blank line.
@@ -270,7 +271,19 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
if indent_level:
if not (blank_before or previous_indent_level < indent_level or
DOCSTRING_REGEX.match(previous_logical)):
- yield 0, "E301 expected 1 blank line, found 0"
+ ancestor_level = indent_level
+ nested = False
+ for line in lines[line_number - 2::-1]:
+ if line.strip() and expand_indent(line) < ancestor_level:
+ ancestor_level = expand_indent(line)
+ nested = line.lstrip().startswith('def ')
+ if nested or ancestor_level == 0:
+ break
+ if nested:
+ yield 0, "E306 expected 1 blank line, found 0" \
+ " (nested definition)"
+ else:
+ yield 0, "E301 expected 1 blank line, found 0"
elif blank_before != 2:
yield 0, "E302 expected 2 blank lines, found %d" % blank_before
elif (logical_line and not indent_level and blank_before != 2 and