Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Incorrect syntax highlighting for rf strings #186
Comments
|
Another related problem: microsoft/vscode-python#2445 Update: the lower case |
|
To reiterate: there's a feature highlighting lower-case plt.title(
(f"{label}: " if label else "") + r"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)
plt.title(
(f"{label}: " if label else "") + R"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)
plt.title(
(Rf"{label}: " if label else "") + R"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)The lower-case |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@vpetrovykh Thanks for this advice. Unfortunately, it's not currently usable with |
|
@janosh Use |
|
@elprans IIUC, this has other effects besides preventing r-string prefixes from being lower cased (such as not converting single to double quotes). Btw, just tested it and it works with auto-format on save by adding |
|
I think this decision by the MagicPython devs to apply additional special meaning to a part of the Python language definition is a mistake. I've been wondering for a while why all my raw strings (which are almost never regex's) are highlighted weirdly by VSCode. It's nice to finally understand what's going on but it imposes mysterious behaviour on downstream projects. The simple question is, can this behaviour be disabled by downstream projects by some configuration option? |
|
I have struggled with this issue constantly. Sometimes disable -> enable works and gets the f-strings highlighting back, but when using WSL this is no longer possible. With MagicPython installed I still don't have f-string highlighting: How do I consistently, without needing to install and reinstall, get the f-string highlight? |
FWIW I agree, that probably was my mistake. The problem is that reverting this isn't an option now -- as magicpython is used by GH to highlight Python code and by multiple IDEs. Millions of people use it daily. To be fair, millions of people used TextMate & SublimeText before that also highlighted @vpetrovykh @elprans That said I think that
That seems like a not relevant issue. Perhaps your editor has some plugin that interferes with MagicPython. |
|
Yes, looks like f-strings should be format strings first and foremost, regardless of what other flavor they have. |
|
+1 for handling |
I think that, at least in the case of VSCODE, they might be happy if this behaviour was reverted. I'm not sure about GH or the other IDE devs' opinions; you would know better than me. Would it be possible to overload the parser to provide an alternative API that the IDEs could swap to or expose to their end users to select whether to use the regex-highlighted version or a plain-string version? |
Any f-string allows variable interpolation, that includes a raw f-string. Make all raw prefixes (`r` or `R`) behave the same way in combination with `f` prefix. Fixes #186



Environment data
Expected behavior
If I combine raw strings with formatted string literals (a.k.a. f-strings), I'd expect the syntax highlighting to remain that of f-strings.
Actual behavior
What I'm actually seeing is the dark red color used for raw strings even for parts of the f-string that are Python code and have yet to be evaluated.
Related issues
#6572: This issue was originally opened against the VS Code Python extension.