positron icon indicating copy to clipboard operation
positron copied to clipboard

File path completion in Python on Windows uses `\`

Open ntluong95 opened this issue 1 year ago • 10 comments

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

ntluong95 avatar Jun 30 '24 21:06 ntluong95

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

juliasilge avatar Jul 01 '24 15:07 juliasilge

Yes it is slash in the path

ntluong95 avatar Jul 01 '24 17:07 ntluong95

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

juliasilge avatar Jul 22 '24 21:07 juliasilge

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

image

ntluong95 avatar Jul 23 '24 06:07 ntluong95

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!

juliasilge avatar Jul 23 '24 17:07 juliasilge

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 avatar Jul 24 '24 02:07 kevinushey

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'

kevinushey avatar Jul 24 '24 02:07 kevinushey

That's a great point; thanks.

juliasilge avatar Jul 24 '24 16:07 juliasilge

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!

StefanMunnes avatar Aug 30 '24 09:08 StefanMunnes

Just adding a comment relative to something I saw in my class last night; this is creeping up with a few students on Windows machines. https://github.com/posit-dev/positron/discussions/5002

Btibert3 avatar Oct 11 '24 17:10 Btibert3

Verified Fixed

Positron Version(s) : 2025.03.0-11 OS Version(s) : Windows 11

Test scenario(s)

Autocomplete now adds appropriate escaping for paths on windows

Image

Link(s) to TestRail test cases run or created:

jonvanausdeln avatar Feb 11 '25 17:02 jonvanausdeln