Skip to content
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

In Python 3.8, use the stdlib ast instead of typed_ast #6539

Merged
merged 19 commits into from
Mar 15, 2019

Conversation

gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Mar 12, 2019

This required mostly changes to fastparse.py, plus a smattering of other things. The tests still don't all pass, but I believe all remaining errors are due to differences in error messages for SyntaxError between typed_ast and Python 3.8's ast (where a bunch of improvements and spelling changes were made, including "can't" -> "cannot").

To test, you need python/cpython#12295 (else it crashes due to ast.Constant not having a kind field). UPDATE: That landed today, March 13.

UPDATE: This also requires a typeshed sync to incorporate python/typeshed#2859; I've send a PR to typeshed as #6540. UPDATE^2: Those have landed.

Guido van Rossum added 6 commits March 12, 2019 20:36
… in Python 3.8

We shouldn't need to test parser errors anyways
I changed visit_NameConstant() to set the line number, and this caused
the HTML report to flag the line 'assert False' as precise (correct)
rather than as empty (wrong).
(My tox-fu is too weak to make this work -- it still tries to run Python 3.7.)

This reverts commit 8c24cd8.
@gvanrossum gvanrossum changed the title [WIP] In Python 3.8, use the stdlib ast instead of typed_ast In Python 3.8, use the stdlib ast instead of typed_ast Mar 14, 2019
@gvanrossum
Copy link
Member Author

At some point tomorrow I hope the Python 3.8-dev build will include python/cpython#12295 and then the tests should all pass.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks! Mostly looks good, just few minor suggestions.

mypy/fastparse.py Show resolved Hide resolved
mypy/fastparse.py Outdated Show resolved Hide resolved
mypy/fastparse.py Outdated Show resolved Hide resolved
mypy/fastparse.py Outdated Show resolved Hide resolved
@ilevkivskyi
Copy link
Member

Oh, my review crossed with some updates and this is no more WIP.

@gvanrossum
Copy link
Member Author

After a job restart, the tests passed (meaning python/cpython#12295 made it into Travis's "3.8-dev"). Maybe @jukka can greenlight this?

@gvanrossum
Copy link
Member Author

@ilevkivskyi Can you review this one more time? @JukkaL told me offline he's fine with it.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks for updates! LGTM.

@@ -1094,7 +1177,7 @@ def invalid_type(self, node: AST, note: Optional[str] = None) -> RawExpressionTy
def visit(self, node: ast3.expr) -> Type: ...

@overload # noqa
def visit(self, node: Optional[AST]) -> Optional[Type]: ...
def visit(self, node: Optional[AST]) -> Optional[Type]: ... # noqa
Copy link
Member

Choose a reason for hiding this comment

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

It's sad this #noqa is still needed. The issue PyCQA/pyflakes#434 was fixed two weeks ago, so we will be able to update flake8 and remove these soon.

@gvanrossum gvanrossum merged commit 69a5a02 into python:master Mar 15, 2019
@gvanrossum gvanrossum deleted the use-py38 branch March 15, 2019 20:38
@bluetech
Copy link
Contributor

Does it makes sense to add a ; python_version < "3.8" environment marker to the typed_ast requirement in setup.py? This way mypy won't pull typed_ast on Python >= 3.8.

msullivan added a commit that referenced this pull request Mar 15, 2019
Remove the conditional method definition added in #6539, which mypyc
doesn't support.
@gvanrossum
Copy link
Member Author

No, it’s still needed for 2.7.

msullivan added a commit that referenced this pull request Mar 15, 2019
#6554)

Remove the conditional method definition added in #6539, which mypyc
doesn't support.
@bluetech
Copy link
Contributor

2.7 is included in < "3.8".

The idea is to avoid needlessly installing a package when it's not needed, similar to how the typing package is only pulled by mypy for Python < 3.5.3.

@emmatyping
Copy link
Collaborator

@bluetech, I believe Guido means "It's needed to parse 2.7 on Python 3". Mypy only runs under Python 3, which means to type check Python 2 code we still need typed_ast.

@bluetech
Copy link
Contributor

Ha, I misunderstood. That makes sense.

gvanrossum pushed a commit that referenced this pull request May 7, 2019
Fixes #3871. This change fixes a few things concerning class/function definition line numbers.

For users running mypy with Python 3.8+:
- Function definitions are now reported on the correct line, rather than the line of the first decorator plus the number of decorators.
- Class definitions are now reported on the correct line, rather than the line of the first decorator.
- **These changes are fully backward compatible with respect to `# type: ignore` lines**. In other words, existing comments will _not_ need to be moved. This is accomplished by defining an ignore "scope" just like we added to expressions with #6648. See the recent discussion at #3871 for reasoning.

For other users (running mypy with Python 3.7 or earlier):
- Class definition lines are reported by using the same decorator-offset estimate as functions. This is both more accurate, and necessary to get 15 or so tests to pass for both pre- and post-3.8 versions. This seems fine, since there [doesn't appear](#6539 (comment)) to be a compelling reason why it was different in the first place.
- **This change is also backward-compatible with existing ignores, as above.**

About 15 tests had to have their error messages / nodes moved down one line, and 4 new regression tests have been added to `check-38.test`.
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.

4 participants