Skip to content

Module docstrings in 3.7 are not part of Module node anymore #3531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2018

Conversation

hroncok
Copy link
Member

@hroncok hroncok commented Jun 4, 2018

Fixes #3530

@@ -70,10 +70,16 @@ class TestAssertionRewrite(object):
def test_place_initial_imports(self):
s = """'Doc string'\nother = stuff"""
m = rewrite(s)
# Module docstrings in 3.7 are part of Module node, it's not in the body
# Module docstrings in 3.8 are part of Module node, it's not in the body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know for sure it will change in 3.8, or do we need a tracking issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, let's ask @ncoghlan

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not sure yet what's going to happen in 3.8, as the key point that we didn't take into account this time around is the significant difference that moving module docstrings around creates between doing ast.parse("'Hello'", mode="exec").body[0].value and ast.parse("'Hello'", mode="eval").body.

I suspect what we'll end up going with is Naoki Inada's idea of introducing a dedicated DocString node into the AST, since that still allows a bunch of special case heuristics in the compiler to be tidied up (since they can dispatch directly on node type instead), without losing the location information for the docstring, and without making them disappear from the node tree entirely.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please take a look at my comment and let's see if we need to update the comment as @RonnyPfannschmidt mentioned.

Thanks @hroncok!

# We have a complicated sys.version_info if in here to ease testing on
# various Python 3.7 versions, but we should remove the 3.7 check after
# 3.7 is released as stable
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the check to its own function, moving the explanatory comment to its docstring? This will make the code easier to follow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# Module docstrings in some new Python versions are part of Module node
# It's not in the body so we remove it so the following body items have
# the same indexes on all Python versions:
if python_version_has_docstring_in_module_node():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the nitpick, since in all 3 cases the following code is the same can we please factor it over as well

Copy link
Member Author

@hroncok hroncok Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed in 8dff229. Feel free to squash or not squash when merging.

@coveralls
Copy link

coveralls commented Jun 4, 2018

Coverage Status

Coverage increased (+0.05%) to 92.753% when pulling 39ebdab on hroncok:370b5 into d609b63 on pytest-dev:master.

various Python 3.7 versions, but we should remove the 3.7 check after
3.7 is released as stable to make this check more straightforward.
"""
if sys.version_info < (3, 8) or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, it might not work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it doesn't. The second part should be inverted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased.

assert isinstance(m.body[0], ast.Expr)
assert isinstance(m.body[0].value, ast.Str)
del m.body[0]
return m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a mutating helper, i propose not having a return value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do it in place? ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done, thanks for all the timely followups with the nitpicks,

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@hroncok
Copy link
Member Author

hroncok commented Jun 4, 2018

NB: I've checked that tests pass with both 3.7.0b4 and 3.7.0b5.

@RonnyPfannschmidt RonnyPfannschmidt merged commit 7f5cb46 into pytest-dev:master Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants