More small fixes regarding docstrings.

This commit is contained in:
Dave Halter
2017-07-21 19:56:04 +02:00
parent 97b98a1da3
commit 9e5d6db24a
3 changed files with 11 additions and 3 deletions

View File

@@ -42,13 +42,14 @@ def _is_future_import_first(import_from):
"""
found_docstring = False
for stmt in _iter_stmts(import_from.get_root_node()):
if stmt.type == 'string' and not found_docstring:
continue
found_docstring = True
if stmt == import_from:
return True
if stmt.type == 'import_from' and _is_future_import(stmt):
continue
if stmt.type == 'string' and not found_docstring:
found_docstring = True
continue
return False

View File

@@ -230,7 +230,13 @@ class PEP8Normalizer(ErrorFinder):
if child.type == 'simple_stmt':
# Remove the newline.
children = child.children[:-1]
found_docstring = False
for c in children:
if c.type == 'string' and not found_docstring:
continue
found_docstring = True
if c.type == 'expr_stmt' and \
all(_is_magic_name(n) for n in c.get_defined_names()):
continue

View File

@@ -170,3 +170,4 @@ def test_future_import_first():
assert is_issue('1\n' + i1)
assert is_issue('"";1\n' + i1)
assert is_issue('""\n%s\nfrom x import a\n%s', i1, i2)
assert is_issue('%s\n""\n%s', i1, i2)