Skip to content

Commit c780d1f

Browse files
authored
Merge pull request #4723 from asottile/docstring_fix_py38
Remove workaround for docstrings for py38+
2 parents a945734 + 3153740 commit c780d1f

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

testing/test_assertrewrite.py

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,16 @@ def getmsg(f, extra_ns=None, must_pass=False):
6868
pytest.fail("function didn't raise at all")
6969

7070

71-
def adjust_body_for_new_docstring_in_module_node(m):
72-
"""Module docstrings in 3.8 are part of Module node.
73-
This was briefly in 3.7 as well but got reverted in beta 5.
74-
75-
It's not in the body so we remove it so the following body items have
76-
the same indexes on all Python versions:
77-
78-
TODO:
79-
80-
We have a complicated sys.version_info if in here to ease testing on
81-
various Python 3.7 versions, but we should remove the 3.7 check after
82-
3.7 is released as stable to make this check more straightforward.
83-
"""
84-
if sys.version_info < (3, 8) and not (
85-
(3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
86-
):
87-
assert len(m.body) > 1
88-
assert isinstance(m.body[0], ast.Expr)
89-
assert isinstance(m.body[0].value, ast.Str)
90-
del m.body[0]
91-
92-
9371
class TestAssertionRewrite(object):
9472
def test_place_initial_imports(self):
9573
s = """'Doc string'\nother = stuff"""
9674
m = rewrite(s)
97-
adjust_body_for_new_docstring_in_module_node(m)
98-
for imp in m.body[0:2]:
75+
assert isinstance(m.body[0], ast.Expr)
76+
for imp in m.body[1:3]:
9977
assert isinstance(imp, ast.Import)
10078
assert imp.lineno == 2
10179
assert imp.col_offset == 0
102-
assert isinstance(m.body[2], ast.Assign)
80+
assert isinstance(m.body[3], ast.Assign)
10381
s = """from __future__ import division\nother_stuff"""
10482
m = rewrite(s)
10583
assert isinstance(m.body[0], ast.ImportFrom)
@@ -110,24 +88,24 @@ def test_place_initial_imports(self):
11088
assert isinstance(m.body[3], ast.Expr)
11189
s = """'doc string'\nfrom __future__ import division"""
11290
m = rewrite(s)
113-
adjust_body_for_new_docstring_in_module_node(m)
114-
assert isinstance(m.body[0], ast.ImportFrom)
115-
for imp in m.body[1:3]:
91+
assert isinstance(m.body[0], ast.Expr)
92+
assert isinstance(m.body[1], ast.ImportFrom)
93+
for imp in m.body[2:4]:
11694
assert isinstance(imp, ast.Import)
11795
assert imp.lineno == 2
11896
assert imp.col_offset == 0
11997
s = """'doc string'\nfrom __future__ import division\nother"""
12098
m = rewrite(s)
121-
adjust_body_for_new_docstring_in_module_node(m)
122-
assert isinstance(m.body[0], ast.ImportFrom)
123-
for imp in m.body[1:3]:
99+
assert isinstance(m.body[0], ast.Expr)
100+
assert isinstance(m.body[1], ast.ImportFrom)
101+
for imp in m.body[2:4]:
124102
assert isinstance(imp, ast.Import)
125103
assert imp.lineno == 3
126104
assert imp.col_offset == 0
127-
assert isinstance(m.body[3], ast.Expr)
105+
assert isinstance(m.body[4], ast.Expr)
128106
s = """from . import relative\nother_stuff"""
129107
m = rewrite(s)
130-
for imp in m.body[0:2]:
108+
for imp in m.body[:2]:
131109
assert isinstance(imp, ast.Import)
132110
assert imp.lineno == 1
133111
assert imp.col_offset == 0
@@ -136,9 +114,8 @@ def test_place_initial_imports(self):
136114
def test_dont_rewrite(self):
137115
s = """'PYTEST_DONT_REWRITE'\nassert 14"""
138116
m = rewrite(s)
139-
adjust_body_for_new_docstring_in_module_node(m)
140-
assert len(m.body) == 1
141-
assert m.body[0].msg is None
117+
assert len(m.body) == 2
118+
assert m.body[1].msg is None
142119

143120
def test_dont_rewrite_plugin(self, testdir):
144121
contents = {

0 commit comments

Comments
 (0)