universal_pathlib icon indicating copy to clipboard operation
universal_pathlib copied to clipboard

`S3Path` is not a subclass of `Path` anymore

Open Koncopd opened this issue 2 months ago • 2 comments

Is this intended? We rely a lot on a single isinstance check with just Path.

Koncopd avatar Dec 30 '25 11:12 Koncopd

Hi @Koncopd ,

This is intended. universal-pathlib 0.3.x fixed a long standing bug where UPath incorrectly subclassed Path, and inherited the __fspath__ interface. pathlib.Path and os.PathLike classes and subclasses represent local paths.

Since an isinstance check for pathlib.Path does not disentangle if the code after wants to work with the Path methods or wants to hand over a Path object to open, the UPath change is unfortunately breaking a lot of user code. But it's necessary to do the transition to pathlib_abc Base classes and future changes in the python stdlib.

If you provide me with a few links to usage in your code I can recommend the smoothest transition path for you.

In general, I recommend reading the migration guide: https://universal-pathlib.readthedocs.io/en/latest/migration/ And in your case checking for UPath and upcasting pathlib.Path objects to UPath. There's usually little downside to this, since PosixUPath and WindowsUPath behave 99% identical to their pathlib Base classes and have the added benefit of back porting newer stdlib pathlib behavior.

Cheers, Andreas ☺️

ap-- avatar Dec 30 '25 12:12 ap--

Hi, @ap-- .Thank you for the response. So do i understand correctly, that local paths are still subclasses of Path and this will be so in the future? I see that it returns true for isinstance. But cloud paths are not anymore and won't be?

Koncopd avatar Dec 30 '25 14:12 Koncopd