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-strings: do not allow backslashes #72108

Closed
ericvsmith opened this issue Aug 31, 2016 · 12 comments
Closed

f-strings: do not allow backslashes #72108

ericvsmith opened this issue Aug 31, 2016 · 12 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@ericvsmith
Copy link
Member

BPO 27921
Nosy @warsaw, @ericvsmith, @ned-deily, @vadmium, @serhiy-storchaka
Files
  • 27921.patch
  • 27921-1.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ericvsmith'
    closed_at = <Date 2016-09-03.13:18:41.141>
    created_at = <Date 2016-08-31.23:49:40.653>
    labels = ['interpreter-core', 'type-bug', 'release-blocker']
    title = 'f-strings: do not allow backslashes'
    updated_at = <Date 2016-09-07.17:19:58.676>
    user = 'https://github.com/ericvsmith'

    bugs.python.org fields:

    activity = <Date 2016-09-07.17:19:58.676>
    actor = 'eric.smith'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2016-09-03.13:18:41.141>
    closer = 'python-dev'
    components = ['Interpreter Core']
    creation = <Date 2016-08-31.23:49:40.653>
    creator = 'eric.smith'
    dependencies = []
    files = ['44311', '44347']
    hgrepos = []
    issue_num = 27921
    keywords = ['patch']
    message_count = 12.0
    messages = ['274079', '274172', '274235', '274293', '274295', '274296', '274301', '274309', '274329', '274416', '274839', '274843']
    nosy_count = 6.0
    nosy_names = ['barry', 'eric.smith', 'ned.deily', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27921'
    versions = ['Python 3.6']

    @ericvsmith
    Copy link
    Member Author

    See https://mail.python.org/pipermail/python-dev/2016-August/145979.html for details.

    PEP-498 is going to be changed to disallow backslashes inside braces (the expression portions of an f-string).

    However, I can't get that change done in time for 3.6 beta 1. So, this bug will disallow any backslashes in f-strings. Before the next beta, I'll implement the correct behavior.

    This is a breaking change: f-strings like f'\\t{3}' which worked in 3.6 alphas will not work in 3.6 beta 1, but will work in beta 2. f-strings like f'{\'x\'}' which worked in 3.6 alphas, will not work in any beta or release version of 3.6.

    @ericvsmith ericvsmith self-assigned this Aug 31, 2016
    @ericvsmith ericvsmith added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Aug 31, 2016
    @serhiy-storchaka
    Copy link
    Member

    •        result.append(f'  [Previous line repeated {count-3} more times]\\n')
      
    •        result.append(f'  [Previous line repeated {count-3} more times]''\\n')
      

    This looks a little ugly.

    @ericvsmith
    Copy link
    Member Author

    This looks a little ugly.

    True. My goal is to get the simplest possible thing working now, and then before beta 2 fix it so that backslashes again work in the text portions of an f-string. After that, I'll fix this particular piece of code (and the others, plus the tests that can be made to work).

    Here's an updated patch. I'm planning on committing it today.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 3, 2016

    New changeset d7ce127b5c0f by Eric V. Smith in branch 'default':
    Closes bpo-27921: Disallow backslashes anywhere in f-strings. This is a temporary restriction. In 3.6 beta 2, the plan is to again allow backslashes in the string parts of f-strings, but disallow them in the expression parts.
    https://hg.python.org/cpython/rev/d7ce127b5c0f

    @python-dev python-dev mannequin closed this as completed Sep 3, 2016
    @ericvsmith
    Copy link
    Member Author

    See bpo-27948 for adding backslashes back in to the string parts of an f-string.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 3, 2016

    New changeset 899ee1e68a8d by Eric V. Smith in branch 'default':
    bpo-27921: Remove backslash from another f-string.
    https://hg.python.org/cpython/rev/899ee1e68a8d

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 3, 2016

    New changeset 80eb6eb57537 by Eric V. Smith in branch 'default':
    bpo-27921: Remove backslash from another f-string. I'll revert this change before beta 2.
    https://hg.python.org/cpython/rev/80eb6eb57537

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 3, 2016

    New changeset fd4e4fa75260 by Eric V. Smith in branch 'default':
    bpo-27921: Remove backslash from another f-string. I'll revert this change before beta 2. I also need to look in to why test_tools/test_unparse fails with the files that are now being skipped.
    https://hg.python.org/cpython/rev/fd4e4fa75260

    @vadmium
    Copy link
    Member

    vadmium commented Sep 3, 2016

    I haven’t looked, but my guess at why test_unparse could fail would be trying to generate code for an f-string with control characters in. Maybe it is taking stuff like

    f'''{x}
    {y}
    '''

    and generating

    f'{x}\n{y}\n'

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 5, 2016

    New changeset df5b6d1c7ea8 by Benjamin Peterson in branch 'default':
    fix skipping bpo-27921 for windows
    https://hg.python.org/cpython/rev/df5b6d1c7ea8

    @ericvsmith
    Copy link
    Member Author

    The problem with test_unparse is that:
    f'''{"'"}'''
    becomes:
    f'{"\'"}'
    when it's run through Tools/parser/unparse.py.

    I'll open another issue for this.

    @ericvsmith
    Copy link
    Member Author

    bpo-28002 tracks the problem with Tools/parser/unparse.py.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants