Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Implement PEP 526 Variable Annotations Syntax #16

Merged
merged 17 commits into from
Sep 27, 2016

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Sep 14, 2016

@ddfisher @gvanrossum @JukkaL

Here is an implementation of the PEP 526 syntax with minimal changes in typed_ast API. The only externally visible change is:

Assign(expr* targets, expr? value, expr? type_comment)

This requires a tiny change to mypy/fastparse.py, there is an accompanying PR to mypy with this change.

@gvanrossum
Copy link
Member

Since this is just a backport of the corresponding Python 3.6 code I'm going to merge this mostly based on trust. I'll iterate once I've got most things working again.

@gvanrossum
Copy link
Member

Never mind I don't have commit access to this repo, and David's out this week. :-(

@ilevkivskyi
Copy link
Member Author

@gvanrossum
OK, no problem.
Anyway, I changed behaviour a bit in response to your latest e-mail: x: int is now equivalent to x = None # type: int and both are always OK, while x: int = None is flagged as error if --strict-optional.

Did I understand you correct?

I am now testing this and will update PRs (here and at mypy) soon.

@gvanrossum
Copy link
Member

Those behaviors sound okay. I am now testing too. Two administrative nits I found:

  • This PR should bump the version in setup.py
  • Should we rename ast35 to ast36???

@ilevkivskyi
Copy link
Member Author

@gvanrossum

This PR should bump the version in setup.py

OK, will do this

Should we rename ast35 to ast36???

There is also a third option to keep both (see my comment at mypy PR)

This is technically a breaking interface change, so I'm going to bump a major version number.
@ddfisher
Copy link
Collaborator

This isn't compatible with the current mypy, so I'll need to wait until python/mypy#2131 is pushed to PyPI before releasing this.

@ilevkivskyi
Copy link
Member Author

@ddfisher I thought that you are supposed to review and merge python/mypy#2131 That one should work with both old and new versions of typed_ast.

@ddfisher
Copy link
Collaborator

Yep! That's the plan. I just wanted to make a note here about the need to wait for a mypy release before releasing this.

@ddfisher
Copy link
Collaborator

Actually, I chatted with Guido a bit about this, and we'd like to remove that dependency problem. Here's how that could be done: instead of putting the assignment type annotation in the same field as the type comment, leave the type comment field as is and add a new one for the type annotation. This is similar to how function annotations/type comments are handled. Also, I think this would get rid of the need for the new_syntax field, which would be a nice simplification. Would you mind making these changes?

@ilevkivskyi
Copy link
Member Author

OK, I will do this. I will push commits here and to mypy PR together with implementing your comments (not sure that I will have time to do all this today).

@ddfisher
Copy link
Collaborator

Thanks!

@ilevkivskyi
Copy link
Member Author

@ddfisher I updated all the three PRs (here, mypy, and typeshed) taking into account your comments.
Now all four combinations of mypy and typed_ast (old-old, old-new, new-old, new-new) should work.
Please double check.

@ddfisher
Copy link
Collaborator

Had to make some minor tweaks, but this looks good now. Thanks!

@ddfisher ddfisher merged commit 7735bfa into python:master Sep 27, 2016
ddfisher pushed a commit to python/mypy that referenced this pull request Sep 28, 2016
Depends on python/typed_ast#16 for the new syntax, but is backwards compatible otherwise.
ddfisher pushed a commit to python/typeshed that referenced this pull request Sep 28, 2016
tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this pull request Dec 6, 2021
tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this pull request Dec 6, 2021
Previously we returned a string (bytes) object.
tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this pull request Dec 6, 2021
tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this pull request Dec 6, 2021
Issue python#16: accept arbitrary buffer-compatible objects
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants