Skip to content

Commit bdec682

Browse files
committed
Module docstrings in 3.7 are not part of Module node anymore
Fixes #3530
1 parent d609b63 commit bdec682

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

changelog/3530.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix if in tests to support 3.7.0b5, where a docstring handling in AST got reverted.

testing/test_assertrewrite.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,18 @@ class TestAssertionRewrite(object):
7070
def test_place_initial_imports(self):
7171
s = """'Doc string'\nother = stuff"""
7272
m = rewrite(s)
73-
# Module docstrings in 3.7 are part of Module node, it's not in the body
73+
# Module docstrings in 3.8 are part of Module node, it's not in the body
7474
# so we remove it so the following body items have the same indexes on
7575
# all Python versions
76-
if sys.version_info < (3, 7):
76+
# This was briefly in 3.7 as well but got reverted in beta 5
77+
# TODO:
78+
# We have a complicated sys.version_info if in here to ease testing on
79+
# various Python 3.7 versions, but we should remove the 3.7 check after
80+
# 3.7 is released as stable
81+
if (
82+
sys.version_info < (3, 8)
83+
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
84+
):
7785
assert isinstance(m.body[0], ast.Expr)
7886
assert isinstance(m.body[0].value, ast.Str)
7987
del m.body[0]
@@ -92,7 +100,10 @@ def test_place_initial_imports(self):
92100
assert isinstance(m.body[3], ast.Expr)
93101
s = """'doc string'\nfrom __future__ import with_statement"""
94102
m = rewrite(s)
95-
if sys.version_info < (3, 7):
103+
if (
104+
sys.version_info < (3, 8)
105+
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
106+
):
96107
assert isinstance(m.body[0], ast.Expr)
97108
assert isinstance(m.body[0].value, ast.Str)
98109
del m.body[0]
@@ -103,7 +114,10 @@ def test_place_initial_imports(self):
103114
assert imp.col_offset == 0
104115
s = """'doc string'\nfrom __future__ import with_statement\nother"""
105116
m = rewrite(s)
106-
if sys.version_info < (3, 7):
117+
if (
118+
sys.version_info < (3, 8)
119+
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
120+
):
107121
assert isinstance(m.body[0], ast.Expr)
108122
assert isinstance(m.body[0].value, ast.Str)
109123
del m.body[0]
@@ -124,7 +138,10 @@ def test_place_initial_imports(self):
124138
def test_dont_rewrite(self):
125139
s = """'PYTEST_DONT_REWRITE'\nassert 14"""
126140
m = rewrite(s)
127-
if sys.version_info < (3, 7):
141+
if (
142+
sys.version_info < (3, 8)
143+
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
144+
):
128145
assert len(m.body) == 2
129146
assert isinstance(m.body[0], ast.Expr)
130147
assert isinstance(m.body[0].value, ast.Str)

0 commit comments

Comments
 (0)