pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

VS code does not handle escaping braces in f-strings

Open arobinson opened this issue 4 years ago • 5 comments

  • VS Code version: 1.61.1
  • Extension version (available under the Extensions sidebar): 2021.10.1336267007
  • OS and version: Mac OSX 11.6
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.4 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: Pylance

[NOTE: If you suspect that your issue is related to the Microsoft Python Language Server (python.languageServer: 'Microsoft'), please download our new language server Pylance from the VS Code marketplace to see if that fixes your issue]

Expected behaviour

Should correctly parse f-strings with escape sequences

Actual behaviour

Shows an error with a valid f-string

Steps to reproduce:

Add this code to a py file:

enum_name = 'Foo'
print(f'export enum {enum_name} {{')

In this case {{ is the expected python escape sequence to be able to add a { to the output, but VS code is expecting it to be a variable substitution. The code works as expected while executing through the python without errors, it is only the editor showing that the valid syntax is invalid that is the problem

image

Logs

arobinson avatar Oct 19 '21 21:10 arobinson

I don't see a syntax error here, are you referring to the coloring?

I believe that's handled by VS Code's TextMate grammar for Python, but I do not see this when I write the same code:

image

But, you're also missing any sort of coloring at all on the variables, which implies there's something else wrong.

jakebailey avatar Oct 19 '21 21:10 jakebailey

Without bracket pair colorization:

image

jakebailey avatar Oct 19 '21 21:10 jakebailey

Thanks for the report. Could you please add the information in the report as described in the troubleshooting guide?

judej avatar Oct 20 '21 17:10 judej

I'll check my extensions, but in my screen shot you will see the closing parenthesis in red instead of yellow

arobinson avatar Oct 22 '21 01:10 arobinson

the coloring issue is on textmate. except that, I dont see any issue on the repro code. parser is parsing the code correctly.

heejaechang avatar Apr 11 '22 23:04 heejaechang