◐ Shell
reader mode source ↗
Skip to content

bpo-35766: Merge typed_ast back into CPython#11645

Merged
ambv merged 49 commits into
python:masterfrom
gvanrossum:ast-type-comments
Jan 31, 2019
Merged

bpo-35766: Merge typed_ast back into CPython#11645
ambv merged 49 commits into
python:masterfrom
gvanrossum:ast-type-comments

Conversation

@gvanrossum

@gvanrossum gvanrossum commented Jan 22, 2019

Copy link
Copy Markdown
Member

[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 async or await as a non-keyword. But I could structure this as a follow-up PR, much smaller in size.)

https://bugs.python.org/issue35766

@gvanrossum

Copy link
Copy Markdown
Member Author

I updated the PR to be merged with master now #11605 has been merged. Everything still works, and there are no more "ghost commits" from #11605.

@gvanrossum

gvanrossum commented Jan 22, 2019

Copy link
Copy Markdown
Member Author

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).

  • test_ast.py
  • test_asdl_parser.py
  • test_syntax.py
  • test_exceptions.py
  • test_parser.py

@gvanrossum

gvanrossum commented Jan 23, 2019

Copy link
Copy Markdown
Member Author

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, test_syntax and test_exceptions. Both are failing because the grammar changes have made it so that

if 1:
foo()

reports SyntaxError instead of IndentationError at the start of line 2. The reason for that is this definition in Grammar:

# the TYPE_COMMENT in suites is only parsed for funcdefs, but can't go elsewhere due to ambiguity
suite: simple_stmt | NEWLINE [TYPE_COMMENT NEWLINE] INDENT stmt+ DEDENT

Previously this was

suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT

and there is code in Python/pythonrun.c::err_input that depends on INDENT being the only possibility after the NEWLINE.

I haven't figured out how to fix this yet.

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.
57 hidden items Load more…
Also:
- remove redundant 'c' argument from new_type_comment()
- double-check that TYPE_COMMENT in a suite is followed by NL
@gvanrossum

Copy link
Copy Markdown
Member Author

Sorry for the flood of comments. I believe I've done or responded to every code review comment. Hopefully tests will pass now.

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Thanks for updates! This looks ready, I left a bunch of really minor comments.

@gvanrossum

Copy link
Copy Markdown
Member Author

@ambv Should I just merge this, or do you want to review it?

@ambv

ambv commented Jan 30, 2019

Copy link
Copy Markdown
Contributor

Unless you're in a hurry now, I'll review and stamp it tomorrow morning my time. Mostly to familiarize myself with the changes.

@gvanrossum

Copy link
Copy Markdown
Member Author

That's fine!

@gvanrossum

Copy link
Copy Markdown
Member Author

Unsure why the Appveyor build isn't running?

@zooba

zooba commented Jan 30, 2019

Copy link
Copy Markdown
Member
      Unsure why the Appveyor build isn't running?

It looks it decided to skip the build, maybe because the last commit is a merge?

image

@ambv ambv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide 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.

@ambv ambv merged commit dcfcd14 into python:master Jan 31, 2019
@pablogsal

Copy link
Copy Markdown
Member

@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.

@gvanrossum gvanrossum deleted the ast-type-comments branch February 1, 2019 23:29
tyomitch added a commit to tyomitch/cpython that referenced this pull request Feb 5, 2019
pythonGH-11645 added the fourth option for `mode` argument; updating the comment accordingly.
@tyomitch

tyomitch commented Feb 5, 2019

Copy link
Copy Markdown
Contributor

This PR added a fourth option for mode argument of builtin_compile_impl(), but didn't update its documentation; please see GH-11762

msullivan added a commit to python/typed_ast that referenced this pull request Feb 6, 2019
This is mostly cribbed from python/cpython#11645,
though it also adds a new error check to new_type_comment itself.
gvanrossum pushed a commit to python/typed_ast that referenced this pull request Feb 6, 2019
This is mostly cribbed from python/cpython#11645,
though it also adds a new error check to new_type_comment itself.
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.

8 participants