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

Enable comparing filesystems with == #519

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Enable comparing filesystems with == #519

wants to merge 3 commits into from

Conversation

tfeldmann
Copy link
Contributor

Type of changes

  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • 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.

@willmcgugan
Copy link
Member

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.

@tfeldmann
Copy link
Contributor Author

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 👍

@lurch
Copy link
Contributor

lurch commented Jan 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants