Skip to content

python3: a # in an f-string breaks syntax highlighting #225

Closed
@Spectre5

Description

@Spectre5

See the code below. Since my issue exists on github, I can simply demonstrate my exact issue with the example code block below. Basically, when a # is used within an f-string, then it appears to break the syntax highlighting. It looks like the "#" in the f-string gets interpreted as the start of a comment, even though this is correctly handled for non-f-srings. The # in the format string is used to get the alternate form for the hex conversion. Here is an example of what the "#" does in a format string as well as demonstrate the bug:

>>> # syntax highlighting works here...
>>> i = 5
>>> '{:#04x}'.format(i)   # <-- not using an f-string is fine
'0x05'
>>> f'{i:04x}'
'0005'
>>> f'{i:#04x}'           # <---- this line breaks the syntax highlighting
'0x05'
>>> f'{i:04x}'            # <-- syntax highlighting is broken!
'0005'
>>> '{:#04x}'.format(i)   # <-- syntax highlighting is broken!
'0x05'
>>> 

Here is a screenshot to demonstrate the issue (for future reference) since, after this bug is fixed, the code above will presumably have the correct highlighting:

Screenshot from 2020-11-26 01-22-51

Edit: corrected the 4th output from 0x05 to 0005

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions