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

f-string support #2265

Closed
refi64 opened this issue Oct 17, 2016 · 13 comments
Closed

f-string support #2265

refi64 opened this issue Oct 17, 2016 · 13 comments

Comments

@refi64
Copy link
Contributor

refi64 commented Oct 17, 2016

Right now neither mypy's parser nor the fast parser can even parse them, let alone type-check them!

Since this is probably kind of complicated, I'd think it'd be easier to basically treat them like normal strings first and then move on to full type-checking.

@gvanrossum gvanrossum added this to the 0.5 milestone Oct 17, 2016
@gvanrossum
Copy link
Member

That sounds like a reasonable plan. Do you feel comfortable with implementing it?

@refi64
Copy link
Contributor Author

refi64 commented Oct 17, 2016

👍

@refi64
Copy link
Contributor Author

refi64 commented Oct 17, 2016

@gvanrossum Haha, this is a bit more complicated than I thought. :O

So, typed_ast hasn't been updated for Python 3.6, probably since it hasn't actually been released yet. So it doesn't parse f-strings. There are two ways to fix this:

  • Update typed_ast for the Python 3.6 beta, then update it again when it's officially released in December.
  • Wait until the 3.6 release, and then update typed_ast.
  • Until 3.6 is released, change typed_ast to treat f-strings like normal strings, with absolutely nothing special about them. When 3.6 is released, update typed_ast.

Which would you prefer?

@gvanrossum
Copy link
Member

gvanrossum commented Oct 17, 2016 via email

@refi64
Copy link
Contributor Author

refi64 commented Oct 17, 2016

@gvanrossum So, just to be clear, you mean option 1, right?

@gvanrossum
Copy link
Member

gvanrossum commented Oct 17, 2016 via email

@ilevkivskyi
Copy link
Member

@kirbyfan64 Note that you could not just "copy" what is in Python 3.6b to typed_ast, there are many important bookkeeping (like manually updating entry points that are not updated correctly by pgen etc). When implementing PEP 526, I did not include parts from ast.c only necessary for Python runtime, and also modified ASDL not to match Python's one, but rather to match mypy's one.

If you will need some help while implementing f-strings in typed_ast, then I will be glad to help.

@achauve
Copy link
Contributor

achauve commented Dec 29, 2016

Python 3.6 has been released but mypy doesn't seem to support f-strings (even with mypy-lang-0.4.7.dev0 using the latest git commit as of now).
What is the roadmap concerning the support f-strings? Thanks!

@gvanrossum
Copy link
Member

We're waiting for python/typed_ast#22 to be reviewed and merged (presumably once @ddfisher is back from the holiday break), and pushed to PyPI as a new release. Then we need changes to mypy to use that. But you (== anyone reading this) can help by working on the mypy changes now.

@achauve
Copy link
Contributor

achauve commented Dec 30, 2016

Thanks @gvanrossum! Could you give some indications on the changes required on mypy after the PR on typed_ast has been merged? (not to type check f-strings but just not to break on a code where f-strings are used)

@yan12125
Copy link

After python/typed_ast#22 merged, visit_JOINEDSTR should be implemented in mypy/fastparse.py so that it can handle f-strings.

@gvanrossum
Copy link
Member

Adding some search keywords: string formatting, literal string interpolation, PEP 498.

JukkaL pushed a commit that referenced this issue Feb 21, 2017
@refi64
Copy link
Contributor Author

refi64 commented Mar 14, 2017

Already merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants