diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 105408c..edc8b3e 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -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 diff --git a/parso/python/pep8.py b/parso/python/pep8.py index c08243e..58e4dd3 100644 --- a/parso/python/pep8.py +++ b/parso/python/pep8.py @@ -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 diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 9b8adf2..4c59879 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -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)