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

SyntaxError when using dict key in fstring #90463

Closed
Samisafool mannequin opened this issue Jan 8, 2022 · 5 comments
Closed

SyntaxError when using dict key in fstring #90463

Samisafool mannequin opened this issue Jan 8, 2022 · 5 comments
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@Samisafool
Copy link
Mannequin

Samisafool mannequin commented Jan 8, 2022

BPO 46305
Nosy @ericvsmith, @sobolevn, @Samisafool
Files
  • test.py
  • 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 = None
    closed_at = <Date 2022-01-08.08:55:38.491>
    created_at = <Date 2022-01-08.07:54:07.259>
    labels = ['interpreter-core', '3.8', '3.9', '3.10', 'invalid', 'type-crash']
    title = 'SyntaxError when using dict key in fstring'
    updated_at = <Date 2022-01-08.19:09:43.810>
    user = 'https://github.com/Samisafool'

    bugs.python.org fields:

    activity = <Date 2022-01-08.19:09:43.810>
    actor = 'eric.smith'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-08.08:55:38.491>
    closer = 'Samisafool'
    components = ['Interpreter Core']
    creation = <Date 2022-01-08.07:54:07.259>
    creator = 'Samisafool'
    dependencies = []
    files = ['50550']
    hgrepos = []
    issue_num = 46305
    keywords = []
    message_count = 5.0
    messages = ['410079', '410081', '410082', '410084', '410105']
    nosy_count = 3.0
    nosy_names = ['eric.smith', 'sobolevn', 'Samisafool']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue46305'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @Samisafool
    Copy link
    Mannequin Author

    Samisafool mannequin commented Jan 8, 2022

    SyntaxError when using dict key in fstring

    Attached is a python file where this bug is visible.
    The error is different on CPython 3.8 and 3.9/3.10, interestingly.
    Occurs on CPython 3.8-10 and PyPy 3.8 7.3.7

    Not sure which component to select, never filed a python bug report before. Hopefully this is correct.

    @Samisafool Samisafool mannequin added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 8, 2022
    @sobolevn
    Copy link
    Member

    sobolevn commented Jan 8, 2022

    Can you please try this:

    dict1 = {
            "key1": "test"
            }
    
    print(dict1["key1"])
    
    print(f"key1 is {dict1['key1']}!")
    

    The problem with your code is that dict1["key1"] used the same quotes as f"".

    @Samisafool
    Copy link
    Mannequin Author

    Samisafool mannequin commented Jan 8, 2022

    Is that intended behaviour? It works though.

    @Samisafool
    Copy link
    Mannequin Author

    Samisafool mannequin commented Jan 8, 2022

    Huh, it does seem to be intentional.

    @Samisafool Samisafool mannequin closed this as completed Jan 8, 2022
    @Samisafool Samisafool mannequin added the invalid label Jan 8, 2022
    @Samisafool Samisafool mannequin closed this as completed Jan 8, 2022
    @Samisafool Samisafool mannequin added the invalid label Jan 8, 2022
    @ericvsmith
    Copy link
    Member

    Yes, the behavior is intentional. It might be relaxed in the future.

    @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 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants