Skip to content

Missing the f-prefix on an f-string is hard to notice #65

Open

Description

@Lilja

As python 3.6 gave us f-strings it's I've been using them more over the ol' .format() syntax.

Sadly, the syntax is highlighting strings that have curly braces but have neither f-string prefix or .format suffix.

IMG

The third statement ("{hello}") shouldn't show the curly brace because that is not doing anything fancy with the string. It's just a string.

This might lead me as a developer to miss putting the f-prefix before a string, as the curly braces are giving an indication that they are treated as some sort of templates.

Any thoughts on this?

Activity

  1. nfnty commented on Apr 9, 2020

    @nfnty
    Member

    I've had the same issue from time to time, so this would be a nice improvement. PR is welcome.

  2. vEnhance commented on Nov 11, 2022

    @vEnhance

    Since I never use "...".format the following hack has been helpful to me (after/syntax/python.vim):

    syn match pythonStrFormatNotFString "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString
    hi pythonStrFormatNotFString ctermbg=88 ctermfg=225 guibg=#870000 guifg=#ffd7ff
    
    syn match pythonStrFormatRawString "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonRawString
    hi pythonStrFormatRawString ctermbg=94 ctermfg=229 guibg=#875f00 guifg=#ffffaf

    It's just copying the original pythonStrFormat and changing the containedIn field.

    image

  3. bgenchel commented on Feb 8, 2024

    @bgenchel

    is this solved or being worked on?

  4. Lilja commented on Feb 9, 2024

    @Lilja
    Author

    I would consider looking at nvim that has treesitter integration natively. It doesn't have this issue.

  5. adigitoleo commented on Mar 10, 2024

    @adigitoleo

    Related: #95

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions