posit-dev / positron

Positron, a next-generation data science IDE
Other
2.48k stars 77 forks source link

File path completion in Python on Windows uses `\` #3758

Open ntluong95 opened 3 months ago

ntluong95 commented 3 months ago

Positron Version:

Positron Version: 2024.06.1 (system setup) build 2024.06.1-27 Code - OSS Version: 1.90.0 Commit: a893e5b282612ccb2200102957ac38d3c14e5196 Date: 2024-06-26T01:33:58.809Z Electron: 29.4.0 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Windows_NT x64 10.0.22621

Steps to reproduce the issue:

  1. Import pandas module
  2. Try to import data with function pd.read_csv(""). The cursor is between the two quotation marks, then trigger the code completion for file path using Ctrl + Space

What did you expect to happen?

Normal slash direction for Windows 10 in py script Show file path in Jupyter Notebook

Were there any error messages in the output or Developer Tools console?

image

image

juliasilge commented 3 months ago

Just to check @ntluong95 -- do you mean "slash" here? i.e. the slashes in the path?

ntluong95 commented 3 months ago

Yes it is slash in the path

juliasilge commented 2 months ago

Can you say more about what you expected to happen or the problem you observed? I was digging into this and the slash direction during path completion on Windows appears to be correct:

Image

ntluong95 commented 2 months ago

Here is my output. I think the direction of slash should be / instead of \. Sometimes \ can mean escape sequence

image

juliasilge commented 2 months ago

Ah, gotcha; I misunderstood originally what you were saying. I believe the \ is normal for path normalization for Python on Windows, and this path completion comes from Jedi (read more here). If you would like to see a change in this behavior, I recommend you start a discussion over on the Jedi repo. Thanks!

kevinushey commented 2 months ago

IMHO this is worth fixing or working around in Positron, since the current behavior means that path autocompletion is relatively useless for Windows users. (It gives you strings that are invalid and don't actually represent the path completion desired.)

kevinushey commented 2 months ago

As an aside, note that Python will "sometimes" accept escape sequences and translate those to the intended string, but you usually see a warning. For example:

>>> "\s"
<stdin>:1: SyntaxWarning: invalid escape sequence '\s'
'\\s'

But you can't rely on that in general, since escape sequences that do have some meaning won't be transformed like that:

>>> "\b"
'\x08'
juliasilge commented 2 months ago

That's a great point; thanks.

StefanMunnes commented 1 month ago

I wanted to support the observation that inserting the windows backslash as an escape sequence also happens when I copy and paste the path from the context menu of the file explorer. Thanks for your great work!