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.
That sounds like a reasonable plan. Do you feel comfortable with implementing it?
:+1:
@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:
typed_ast for the Python 3.6 beta, then update it again when it's officially released in December.typed_ast.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?
I'd update typed_ast sooner than later. There's a precedent, we've already
got PEP 526 support. (http://mypy.readthedocs.io/en/latest/python36.html)
That was done by @ilevkivskyi.
@gvanrossum So, just to be clear, you mean option 1, right?
Yes.
@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.
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!
We're waiting for https://github.com/dropbox/typed_ast/pull/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.
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)
After dropbox/typed_ast#22 merged, visit_JOINEDSTR should be implemented in mypy/fastparse.py so that it can handle f-strings.
Adding some search keywords: string formatting, literal string interpolation, PEP 498.
Already merged!
Most helpful comment
Already merged!