microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 767 forks source link

VS code does not handle escaping braces in f-strings #1962

Closed arobinson closed 7 months ago

arobinson commented 3 years ago

[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

jakebailey commented 3 years ago

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 commented 3 years ago

Without bracket pair colorization:

image

judej commented 3 years ago

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

arobinson commented 3 years ago

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

heejaechang commented 2 years ago

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

debonte commented 7 months ago

Resolving as a dupe of https://github.com/microsoft/vscode/issues/225179. This is the original issue, but https://github.com/microsoft/vscode/issues/225179 is being actively investigated.