pyfilesystem2
pyfilesystem2 copied to clipboard
Enable comparing filesystems with `==`
Type of changes
- Other
Checklist
- [x] I've run the latest black with default args on new code.
- [x] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
- [x] I've added tests for new code.
- [x] I accept that @PyFilesystem/maintainers may be pedantic in the code review.
Description
This PR enables comparing filesystems with the == operator. Based on the discussion in #515.
Testing the equality of an FS is not something that makes sense across all filesystems. Your default implementation won't work for the more virtual filesystems. Even with the same class and the same syspath for /, a subdirectory may reference different syspaths.
It's also not clear what equality means with a filesystem. A user may reasonably expect that the contents are the same.
I can see why you might need this, but it's not something that should be exposed via __eq__. I'd suggest defining a function with the logic you need. But it probably isn't something that belongs in the core lib.
Testing the equality of an FS is not something that makes sense across all filesystems. Your default implementation won't work for the more virtual filesystems.
That's true. I see equality as "references the same resource", so for example open_fs("~Desktop") == open_fs("~/Desktop"). It's fine if the more virtual ones cannot be compared.
Even with the same class and the same syspath for /, a subdirectory may reference different syspaths.
I didn't know this is possible - can you expand on that? I guess I misunderstood something. Would the same ospath be a better indicator?
It's also not clear what equality means with a filesystem. A user may reasonably expect that the contents are the same.
Never thought about it this way - good point
I can see why you might need this, but it's not something that should be exposed via
__eq__. I'd suggest defining a function with the logic you need. But it probably isn't something that belongs in the core lib.
That's fine, too! In this case feel free to close the PR 👍
Even with the same class and the same syspath for /, a subdirectory may reference different syspaths.
I didn't know this is possible - can you expand on that?
E.g. https://docs.pyfilesystem.org/en/latest/reference/multifs.html or https://docs.pyfilesystem.org/en/latest/reference/mountfs.html