MagicPython icon indicating copy to clipboard operation
MagicPython copied to clipboard

Wrong highlight for raw string

Open alexr00 opened this issue 2 years ago • 5 comments
trafficstars

  • Editor name and version: VS Code 1.81.1
  • Platform: any
  • Color scheme: any
  • MagicPython version: 7d0f2b22a5ad8fccbd7341bc7b7a715169283044
  • A sreenshot: Expected image

Actual: The \ of a raw string is the \ and not the escape character, but the hignlight still treats them as escapes. image

  • 5-10 lines of surrounding code:
print(r"C:\Users\test")

Originally from @AuroraTea in https://github.com/microsoft/vscode/issues/190519

alexr00 avatar Aug 16 '23 14:08 alexr00

The issue was mentioned here back in 2020. The link contains some extra information that may be helpful.

The issue was closed there so that it could be reported somewhere more relevant instead, namely this repository.

goldrik avatar Sep 12 '23 18:09 goldrik

apparently it is a feature. Check this reply: https://github.com/MagicStack/MagicPython/issues/114#issuecomment-349115524

r is for RE, use R for raw string

DG119 avatar Sep 21 '23 14:09 DG119

apparently it is a feature. [...] r is for RE, use R for raw string

AFAIK this is not a standard defined in any PEP, and popular code formatter such as black will convert any R'' strings into r'' by default.

I get the reasoning behind this decision, and there were some arguments for it since TextMate and Sublime Text both highlight Python syntax this way by default, but with the widespread use of VSCode these days (which does not highlight raw strings in Python this way by default) this argument seems outdated. Ideally this idiosyncratic highlighting could be made optional, preferably off by default.

gilbertohasnofb avatar Jan 06 '24 15:01 gilbertohasnofb

AFAIK this is not a standard defined in any PEP, and popular code formatter such as black will convert any R'' strings into r'' by default.

Black specifically does not change R'' to r'' because of syntax highlighters treating the two differently. See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings.

JelleZijlstra avatar Apr 29 '24 23:04 JelleZijlstra