pylance-release
pylance-release copied to clipboard
VS code does not handle escaping braces in f-strings
- 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.languageServersetting: 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

Logs
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:

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

Thanks for the report. Could you please add the information in the report as described in the troubleshooting guide?
I'll check my extensions, but in my screen shot you will see the closing parenthesis in red instead of yellow
the coloring issue is on textmate. except that, I dont see any issue on the repro code. parser is parsing the code correctly.