Recent versions of jupyter notebook highlight the part in curly braces of an f-string as normal code and not as a string. However, if that code part contains a literal string, the quote that closes the f-string is interpreted as a quote starting a new string, and the end of the f-string is not found for highlighting.
This has two consequences:
The code in the rest of the line is highlighted incorrectly. For example, if the f-string is an argument of a function, the closing bracket is shown in red like a string.
If the f-string is inside brackets (function call, list definition etc.), all new lines in the cell are automatically indented to the beginning of the brackets containing the f-string, as if the content of the brackets was continued in a new line.
The following screenshot shows some examples:
All cells are evaluated as expected; only highlighting is broken.
While the first consequence is merely a graphical issue, the second consequence interferes with auto-indentation and heavily affects the user experience since the indentation has to be fixed manually for each new line inserted below the f-string.
I’m using a fresh venv environment with pip as package manager.
Here is some system information:
Recent versions of jupyter notebook highlight the part in curly braces of an f-string as normal code and not as a string. However, if that code part contains a literal string, the quote that closes the f-string is interpreted as a quote starting a new string, and the end of the f-string is not found for highlighting.
This has two consequences:
The code in the rest of the line is highlighted incorrectly. For example, if the f-string is an argument of a function, the closing bracket is shown in red like a string.
If the f-string is inside brackets (function call, list definition etc.), all new lines in the cell are automatically indented to the beginning of the brackets containing the f-string, as if the content of the brackets was continued in a new line.
The following screenshot shows some examples: All cells are evaluated as expected; only highlighting is broken.
While the first consequence is merely a graphical issue, the second consequence interferes with auto-indentation and heavily affects the user experience since the indentation has to be fixed manually for each new line inserted below the f-string.
I’m using a fresh
venv
environment withpip
as package manager. Here is some system information: