microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.58k stars 29.03k forks source link

Raw string's scope error #152698

Closed Binaryify closed 2 years ago

Binaryify commented 2 years ago

Environment data

Version: 1.68.1 (Universal) Commit: 30d9c6cd9483b2cc586687151bcbcd635f373630 Date: 2022-06-14T12:52:13.188Z Electron: 17.4.7 Chromium: 98.0.4758.141 Node.js: 16.13.0 V8: 9.8.177.13-electron.0 OS: Darwin arm64 21.4.0

Code Snippet

import re

from cv2 import imread

img = imread(r"paper\cell_b.png")

print(r'paper\cell_b.png' == 'paper\\cell_b.png')

image

r'paper\cell_b.png' == 'paper\\cell_b.png' is evaluated as True in Python. Raw string has "r" before it, and it means string without backslash escape in Python. It's especially useful for handling paths in Windows.

the origin issue: https://github.com/Binaryify/OneDark-Pro/issues/749

erictraut commented 2 years ago

This appears to be a bug in the textmate grammar for Python. This grammar is built in to VS Code, not shipped as part of Pylance, which is correctly tokenizing and parsing raw strings. We'll need to work with the VS Code team to get this fixed.

alexr00 commented 2 years ago

@Binaryify and @erictraut I am not a frequent Python user, so please correct me if I've misunderstood something, but I think this is a feature: https://github.com/MagicStack/MagicPython/issues/114#issuecomment-349115524 (that's the repo that VS Code pulls our Python syntax highlighting grammar from).

Binaryify commented 2 years ago

@Haoyu-UT

Haoyu-UT commented 2 years ago

@alexr00 Thank you for your comment. I now come to understand that for vscode (and MagicPython) r and R are interpreted differently. I'm sorry for my ignorance. @Binaryify Thank you for your support. Please kindly close the original issue.