Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.12 slots not accessible in 3.11 #339

Open
lmmx opened this issue Feb 4, 2025 · 1 comment
Open

Python 3.12 slots not accessible in 3.11 #339

lmmx opened this issue Feb 4, 2025 · 1 comment
Labels
question ❓ Further information is requested

Comments

@lmmx
Copy link

lmmx commented Feb 4, 2025

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?

@ap--
Copy link
Collaborator

ap-- commented 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.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.

Compare the following on Python3.11

>>> import sys
>>> sys.version
'3.12.8 (main, Dec  3 2024, 18:42:41) [Clang 16.0.0 (clang-1600.0.26.4)]'
>>>
>>> import upath
>>> upath.__version__
'0.2.6'
>>>
>>> p0 = upath.UPath("./abc.txt")
>>> p0
PosixUPath('abc.txt')
>>> p0._raw_paths
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/andreaspoehlmann/Development/universal_pathlib/upath/core.py", line 463, in __getattr__
    raise AttributeError(item)
AttributeError: _raw_paths
>>>
>>> p1 = upath.UPath("./abc.txt", protocol="file")
>>> p1
FilePath('file:///Users/andreaspoehlmann/Development/universal_pathlib/abc.txt')
>>> p1._raw_paths
['./abc.txt']
>>> 

The next release of universal-pathlib will likely change how all of this handled, but it needs some more thought.

@ap-- ap-- added the question ❓ Further information is requested label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants