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

Inaccurate error message for f-string #79675

Closed
seblin mannequin opened this issue Dec 14, 2018 · 6 comments
Closed

Inaccurate error message for f-string #79675

seblin mannequin opened this issue Dec 14, 2018 · 6 comments
Assignees
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@seblin
Copy link
Mannequin

seblin mannequin commented Dec 14, 2018

BPO 35494
Nosy @ericvsmith, @serhiy-storchaka
PRs
  • bpo-35494: Improve syntax error messages for unbalanced parentheses in f-string. #11161
  • Dependencies
  • bpo-33306: Improving SyntaxError for unmatched parentheses
  • 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/serhiy-storchaka'
    closed_at = <Date 2019-01-12.07:47:17.498>
    created_at = <Date 2018-12-14.13:34:17.302>
    labels = ['interpreter-core', 'type-feature', '3.8']
    title = 'Inaccurate error message for f-string'
    updated_at = <Date 2019-01-12.07:47:17.497>
    user = 'https://bugs.python.org/seblin'

    bugs.python.org fields:

    activity = <Date 2019-01-12.07:47:17.497>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2019-01-12.07:47:17.498>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2018-12-14.13:34:17.302>
    creator = 'seblin'
    dependencies = ['33306']
    files = []
    hgrepos = []
    issue_num = 35494
    keywords = ['patch']
    message_count = 6.0
    messages = ['331827', '331828', '331832', '331833', '331839', '333521']
    nosy_count = 3.0
    nosy_names = ['eric.smith', 'serhiy.storchaka', 'seblin']
    pr_nums = ['11161']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35494'
    versions = ['Python 3.8']

    @seblin
    Copy link
    Mannequin Author

    seblin mannequin commented Dec 14, 2018

    Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> spam = 'spam'
    >>> f'{spam[0}'
      File "<stdin>", line 1
    SyntaxError: f-string: expecting '}'

    The error message seems wrong because a "]" is missing rather than a "}".

    @seblin seblin mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 14, 2018
    @ericvsmith ericvsmith self-assigned this Dec 14, 2018
    @serhiy-storchaka
    Copy link
    Member

    I can take this issue if you do not mind.

    @ericvsmith
    Copy link
    Member

    Go ahead, Serhiy. Thanks!

    @seblin
    Copy link
    Mannequin Author

    seblin mannequin commented Dec 14, 2018

    The same behavior applies to f'{spam[}' and f'{spam(}'. Also to f'{spam{}', but that might be expected.

    This message is more clear:
    >>> f'{spam('
      File "<stdin>", line 1
    SyntaxError: f-string: mismatched '(', '{', or '['

    Perhaps you want to apply that to the above error cases. Then you wouldn't have to catch any type of bracket. :-)

    @serhiy-storchaka
    Copy link
    Member

    PR 11161 uses an approach similar to bpo-33306.

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes type-feature A feature request or enhancement and removed 3.7 (EOL) end of life labels Dec 14, 2018
    @serhiy-storchaka
    Copy link
    Member

    New changeset 58159ef by Serhiy Storchaka in branch 'master':
    bpo-35494: Improve syntax error messages for unbalanced parentheses in f-string. (GH-11161)
    58159ef

    @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
    3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants