fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
251 stars 44 forks source link

UPath with_name, with_stem, with_suffix is broken #72

Closed ap-- closed 2 years ago

ap-- commented 2 years ago
>>> from upath import UPath
>>> UPath("s3://some/file.txt")
S3Path('s3://some/file.txt')
>>> UPath("s3://some/file.txt").with_suffix(".zip")
Traceback (most recent call last):
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/pathlib.py", line 721, in __str__
    return self._str
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/site-packages/upath/core.py", line 125, in __getattr__
    raise AttributeError(item)
AttributeError: _str

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/pathlib.py", line 742, in __repr__
    return "{}({!r})".format(self.__class__.__name__, self.as_posix())
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/pathlib.py", line 734, in as_posix
    return str(self).replace(f.sep, '/')
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/pathlib.py", line 723, in __str__
    self._str = self._format_parsed_parts(self._drv, self._root,
  File "/Users/poehlmann/Environments/envs/pasu/lib/python3.8/site-packages/upath/core.py", line 153, in _format_parsed_parts
    scheme, netloc = self._url.scheme, self._url.netloc
AttributeError: 'NoneType' object has no attribute 'scheme'
>>> 

Fixing this requires overriding those methods with ones based on the pathlib.Path.with_* (python=3.10, probably) versions.