From f0d47409287998f89931bfd1dc7cf9af34b28819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Fri, 12 Jul 2013 18:26:36 +0200 Subject: [PATCH 1/2] a simple fix for nested functions (fixes #28) --- pep8.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pep8.py b/pep8.py index e0035b3d..c00cd17d 100755 --- a/pep8.py +++ b/pep8.py @@ -233,7 +233,7 @@ def maximum_line_length(physical_line, max_line_length): def blank_lines(logical_line, blank_lines, indent_level, line_number, - previous_logical, previous_indent_level): + previous_logical, previous_indent_level, nested_function): r""" Separate top-level function and class definitions with two blank lines. @@ -264,7 +264,8 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number, elif logical_line.startswith(('def ', 'class ', '@')): if indent_level: if not (blank_lines or previous_indent_level < indent_level or - DOCSTRING_REGEX.match(previous_logical)): + DOCSTRING_REGEX.match(previous_logical) or + nested_function): yield 0, "E301 expected 1 blank line, found 0" elif blank_lines != 2: yield 0, "E302 expected 2 blank lines, found %d" % blank_lines @@ -1319,6 +1320,12 @@ def check_logical(self): indent = first_line[:self.mapping[0][1][2][1]] self.previous_indent_level = self.indent_level self.indent_level = expand_indent(indent) + for line in reversed(self.lines[:self.line_number]): + if line.startswith('def '): + self.nested_function = True + break + else: + self.nested_function = False if self.verbose >= 2: print(self.logical_line[:80].rstrip()) for name, check, argument_names in self._logical_checks: From 6ec4af62aaf233bd7871c547018d67cfd4614d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20Ol=C3=A1h?= Date: Fri, 12 Jul 2013 18:28:32 +0200 Subject: [PATCH 2/2] import test case from https://github.com/JensRantil/pep8/commit/82c3a9e28bd3d4019fbc453d79e6937f0e1a08de --- pep8.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pep8.py b/pep8.py index c00cd17d..17e5840c 100755 --- a/pep8.py +++ b/pep8.py @@ -247,6 +247,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number, Okay: def a():\n pass\n\n\ndef b():\n pass Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass + Okay: def a():\n c = 4\n def b():\n pass E301: class Foo:\n b = 0\n def bar():\n pass E302: def a():\n pass\n\ndef b(n):\n pass