Skip to content

f-string support #2265

Closed
Closed

Description

@refi64

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.

Activity

  1. added this to the milestone on Oct 17, 2016
  2. gvanrossum commented on Oct 17, 2016

    @gvanrossum
    Member

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

  3. refi64 commented on Oct 17, 2016

    @refi64
    ContributorAuthor

    👍

  4. refi64 commented on Oct 17, 2016

    @refi64
    ContributorAuthor

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

  5. gvanrossum commented on Oct 17, 2016

    @gvanrossum
    Member
  6. refi64 commented on Oct 17, 2016

    @refi64
    ContributorAuthor

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

  7. gvanrossum commented on Oct 17, 2016

    @gvanrossum
    Member
  8. ilevkivskyi commented on Oct 17, 2016

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

  9. achauve commented on Dec 29, 2016

    @achauve
    Contributor

    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!

  10. gvanrossum commented on Dec 29, 2016

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

  11. achauve commented on Dec 30, 2016

    @achauve
    Contributor

    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)

  12. yan12125 commented on Dec 30, 2016

    @yan12125

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

  13. gvanrossum commented on Feb 16, 2017

    @gvanrossum
    Member

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

  14. refi64 commented on Mar 14, 2017

    @refi64
    ContributorAuthor

    Already merged!

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions