mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-20 03:11:17 +08:00
More small fixes regarding docstrings.
This commit is contained in:
@@ -42,13 +42,14 @@ def _is_future_import_first(import_from):
|
|||||||
"""
|
"""
|
||||||
found_docstring = False
|
found_docstring = False
|
||||||
for stmt in _iter_stmts(import_from.get_root_node()):
|
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:
|
if stmt == import_from:
|
||||||
return True
|
return True
|
||||||
if stmt.type == 'import_from' and _is_future_import(stmt):
|
if stmt.type == 'import_from' and _is_future_import(stmt):
|
||||||
continue
|
continue
|
||||||
if stmt.type == 'string' and not found_docstring:
|
|
||||||
found_docstring = True
|
|
||||||
continue
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,13 @@ class PEP8Normalizer(ErrorFinder):
|
|||||||
if child.type == 'simple_stmt':
|
if child.type == 'simple_stmt':
|
||||||
# Remove the newline.
|
# Remove the newline.
|
||||||
children = child.children[:-1]
|
children = child.children[:-1]
|
||||||
|
|
||||||
|
found_docstring = False
|
||||||
for c in children:
|
for c in children:
|
||||||
|
if c.type == 'string' and not found_docstring:
|
||||||
|
continue
|
||||||
|
found_docstring = True
|
||||||
|
|
||||||
if c.type == 'expr_stmt' and \
|
if c.type == 'expr_stmt' and \
|
||||||
all(_is_magic_name(n) for n in c.get_defined_names()):
|
all(_is_magic_name(n) for n in c.get_defined_names()):
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -170,3 +170,4 @@ def test_future_import_first():
|
|||||||
assert is_issue('1\n' + i1)
|
assert is_issue('1\n' + i1)
|
||||||
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('""\n%s\nfrom x import a\n%s', i1, i2)
|
||||||
|
assert is_issue('%s\n""\n%s', i1, i2)
|
||||||
|
|||||||
Reference in New Issue
Block a user