You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To reiterate: there's a feature highlighting lower-case r strings as regexp, while upper-case R as simply raw. Using upper-case R should get you the result you want. Compare:
plt.title(
(f"{label}: "iflabelelse"") +r"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)
plt.title(
(f"{label}: "iflabelelse"") +R"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)
plt.title(
(Rf"{label}: "iflabelelse"") +R"$y_\mathrm{true}$ vs $y_\mathrm{pred}$"
)
The lower-case r was chosen for the special treatment largely due to a precedent that some existing highlighters offered this convenience already.
@vpetrovykh Thanks for this advice. Unfortunately, it's not currently usable with black formatting since black automatically lower cases r-string prefixes. I opened black#1244 to discuss this.
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?
I think this decision by the MagicPython devs to apply additional special meaning to a part of the Python language definition is a mistake.
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 r'strings' as regexps.
@vpetrovykh@elprans That said I think that fr'strings' shouldn't be highlighted as regexps, so perhaps we should revert that change.
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:
That seems like a not relevant issue. Perhaps your editor has some plugin that interferes with MagicPython.
I think this decision by the MagicPython devs to apply additional special meaning to a part of the Python language definition is a mistake.
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 r'strings' as regexps.
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?
I've had the same problem lately. Drove me crazy.
1.checked all my setting to verify there's no overlap
2.check the extensions folder to verify i don't have inconsistent versions
3.simply re-selected my Interperter+path, and that did the job
Activity
lmcarreiro commentedon Oct 23, 2019
Another related problem: microsoft/vscode-python#2445
Update: the lower case
ris not wrong, it is a feature to use for regex: #114 (comment)vpetrovykh commentedon Oct 23, 2019
To reiterate: there's a feature highlighting lower-case
rstrings as regexp, while upper-caseRas simply raw. Using upper-case R should get you the result you want. Compare:The lower-case
rwas chosen for the special treatment largely due to a precedent that some existing highlighters offered this convenience already.vors commentedon Dec 4, 2019
kelvinwop commentedon Jan 23, 2020
capital R makes it do the fstring highlighting
janosh commentedon Jan 23, 2020
@vpetrovykh Thanks for this advice. Unfortunately, it's not currently usable with
blackformatting sinceblackautomatically lower cases r-string prefixes. I opened black#1244 to discuss this.elprans commentedon Jan 23, 2020
@janosh Use
--skip-string-normalizationfor black to disable the lowercasing behavior.janosh commentedon Jan 23, 2020
@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
skip-string-normalization = trueunder[tool.black]topyproject.toml.gazzar commentedon Feb 2, 2020
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?
Mjb141 commentedon Feb 3, 2020
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?
1st1 commentedon Feb 11, 2020
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
r'strings'as regexps.@vpetrovykh @elprans That said I think that
fr'strings'shouldn't be highlighted as regexps, so perhaps we should revert that change.That seems like a not relevant issue. Perhaps your editor has some plugin that interferes with MagicPython.
vpetrovykh commentedon Feb 12, 2020
Yes, looks like f-strings should be format strings first and foremost, regardless of what other flavor they have.
elprans commentedon Feb 12, 2020
+1 for handling
fr'foo'as f-strings. As for the r-strings, we can probably ship an alternative grammar file and have downstream make their choice.gazzar commentedon Feb 12, 2020
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?
Make raw f-strings consistent.
adamkeinan commentedon May 17, 2021
I've had the same problem lately. Drove me crazy.
1.checked all my setting to verify there's no overlap
2.check the extensions folder to verify i don't have inconsistent versions
3.simply re-selected my Interperter+path, and that did the job
justanotheranonymoususer commentedon Aug 9, 2021
Stumbled upon this today, too. Doesn't make sense and confusing. Would be great to get this fixed.
silkfire commentedon Apr 7, 2022
Why hasn't this been fixed yet? Shouldn't be that hard to add
rto the same highlighting category asR.Make raw f-strings consistent.
Make raw f-strings consistent.