fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
210 stars 36 forks source link

AttributeError: _cparts #202

Closed juftin closed 4 months ago

juftin commented 4 months ago

When upgrading to the new version of universal-pathlib I'm finding it common in my use case for tools to compare UPath instances to pathlib.Path instances and raise an AttributeError:

import pathlib

from upath import UPath

github_path = UPath("github://fsspec:universal_pathlib@main/README.md")
local_path = pathlib.Path("README.md")

match = github_path == local_path
  File "/Users/juftin/Library/Application Support/JetBrains/IntelliJIdea2023.2/scratches/scratch_68.py", line 8, in <module>
    match = github_path == local_path
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/juftin/.pyenv/versions/3.11.3/lib/python3.11/pathlib.py", line 581, in __eq__
    return self._cparts == other._cparts and self._flavour is other._flavour
                           ^^^^^^^^^^^^^
  File "/Users/juftin/git/textual-universal-directorytree/.venv/test/lib/python3.11/site-packages/upath/core.py", line 421, in __getattr__
    raise AttributeError(item)
AttributeError: _cparts. Did you mean: '_parts'?

I'm not exactly sure what pathlib is doing with _cparts, but I'm finding that implementing _cparts and returning self._parts resolves this issue.

ap-- commented 4 months ago

Thanks for reporting @juftin ! The fix will be included in the next version 😃