bpo-35766: Merge typed_ast back into CPython#11645
Conversation
Demo: `compile(sample, "<sample>", "exec", PyCF_ONLY_AST|0x1000)` This will crash if type comments are present. It doesn't *work* yet -- type comments cause crashes in ast.c and type ignore comments aren't passed on to Module yet.
This works, it just needs tests
e1bf919 to
d273d67
Compare
January 22, 2019 17:21
|
I'll try to fix all failing tests before trying again. In my local branch I have test_ast and test_asdl_parser working; the rest is more mysterious (it seems bad indents are parsed differently somehow).
|
Sorry, something went wrong.
a40849b to
36c212b
Compare
January 22, 2019 20:56
|
I may have to put this off for a while (certainly I won't get it into 3.8a1). The main problem at this point is the two failing tests, reports SyntaxError instead of IndentationError at the start of line 2. The reason for that is this definition in Grammar: Previously this was and there is code in Python/pythonrun.c::err_input that depends on I haven't figured out how to fix this yet. |
Sorry, something went wrong.
This fixes if 1: foo() but does nothing about def f(): foo() The latter still reports 'SyntaxError: invalid syntax'. So this is not a real solution, just a stop-gap measure until I find a better solution.
Also: - remove redundant 'c' argument from new_type_comment() - double-check that TYPE_COMMENT in a suite is followed by NL
|
Sorry for the flood of comments. I believe I've done or responded to every code review comment. Hopefully tests will pass now. |
Sorry, something went wrong.
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks for updates! This looks ready, I left a bunch of really minor comments.
Sorry, something went wrong.
|
@ambv Should I just merge this, or do you want to review it? |
Sorry, something went wrong.
|
Unless you're in a hurry now, I'll review and stamp it tomorrow morning my time. Mostly to familiarize myself with the changes. |
Sorry, something went wrong.
|
That's fine! |
Sorry, something went wrong.
|
Unsure why the Appveyor build isn't running? |
Sorry, something went wrong.
It looks it decided to skip the build, maybe because the last commit is a merge? |
Sorry, something went wrong.
ambv
left a comment
There was a problem hiding this comment.
Let's merge this. It's a bit of a bigger change than promised but such is life 😉
I left one comment, @gvanrossum, that you might want to respond to.
Sorry, something went wrong.
|
@ambv @gvanrossum I have detected some refleaks in the buildbots after this PR and I started https://bugs.python.org/issue35881 to track this problem. I already started debugging, but I would like so input in case you can see something obvious right away. |
Sorry, something went wrong.
pythonGH-11645 added the fourth option for `mode` argument; updating the comment accordingly.
|
This PR added a fourth option for |
Sorry, something went wrong.
This is mostly cribbed from python/cpython#11645, though it also adds a new error check to new_type_comment itself.
This is mostly cribbed from python/cpython#11645, though it also adds a new error check to new_type_comment itself.

[UPDATE: I've rewritten this comment to match the latest state of the PR.]
See the bpo issue for motivation. This is the minimal code I hope to merge into CPython. The PR here is complete except for docs. To test this, use
ast.parse(source, type_comments=True).(Speaking of backwards compatibility, my bpo issue suggests that I'd also like some features supporting older grammar versions. The only thing that I would really appreciate is being able to parse code that uses
asyncorawaitas a non-keyword. But I could structure this as a follow-up PR, much smaller in size.)https://bugs.python.org/issue35766