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
{{ message }}
Repository navigation
Accessing private attributes / methods available on pathlib.Path classes? #339
Hi, I don’t know if I’m misunderstanding the nature of the ‘shim’ here but the 3.12 slots are not actually being populated in the UPath as I expected when I found this code. Specifically accessing _raw_paths fails.
I was really hoping to find a backport for this as it’s used in my library to preserve the leading ./ part of relative file paths like ./foo.txt which regular Path “normalises” to foo.txt.
Have I misunderstood the purpose of the shim class or is this a bug?
Thanks for reporting! The issue you're describing is happening because of the way local path handling in universal-pathlib was designed.
To ensure that universal-pathlib's upath.UPath can be used as a drop-in replacement for pathlib.Path it was decided to guarantee as much as possible that the two are compatible for local paths. This is why there are three local path classes in universal-pathlib:
PosixUPath, WindowsUPath and FileUPath.
The first two are basically using the PosixPath and WindowsPath implementations of pathlib. That's why on python<=3.11 none of them populate _raw_paths. FileUPath on the other hand uses fsspec's LocalFileSystem for handling local paths and populates _raw_paths. The distinction is made because fsspec ensures that all relative paths are made absolute, and that changes some of the behavior.
changed the title [-]Python 3.12 slots not accessible in 3.11[/-][+]Accessing private attributes / methods available on pathlib.Path classes on UPath?[/+]on May 9, 2025
changed the title [-]Accessing private attributes / methods available on pathlib.Path classes on UPath?[/-][+]Accessing private attributes / methods available on pathlib.Path classes?[/+]on May 9, 2025
Activity
ap-- commentedon Feb 5, 2025
Hi @lmmx
Thanks for reporting! The issue you're describing is happening because of the way local path handling in universal-pathlib was designed.
To ensure that universal-pathlib's
upath.UPathcan be used as a drop-in replacement forpathlib.Pathit was decided to guarantee as much as possible that the two are compatible for local paths. This is why there are three local path classes in universal-pathlib:PosixUPath,WindowsUPathandFileUPath.The first two are basically using the
PosixPathandWindowsPathimplementations of pathlib. That's why onpython<=3.11none of them populate_raw_paths.FileUPathon the other hand uses fsspec's LocalFileSystem for handling local paths and populates_raw_paths. The distinction is made because fsspec ensures that all relative paths are made absolute, and that changes some of the behavior.Compare the following on Python3.11
The next release of universal-pathlib will likely change how all of this handled, but it needs some more thought.
[-]Python 3.12 slots not accessible in 3.11[/-][+]Accessing private attributes / methods available on pathlib.Path classes on UPath?[/+][-]Accessing private attributes / methods available on pathlib.Path classes on UPath?[/-][+]Accessing private attributes / methods available on pathlib.Path classes?[/+]