Skip to content

Commit

Permalink
Fix equality for AbstractBufferedFile != b'' (#1594)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Durant <martin.durant@alumni.utoronto.ca>
  • Loading branch information
dholth and martindurant committed May 1, 2024
1 parent 05e8858 commit df65747
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,12 @@ def __eq__(self, other):
"""Files are equal if they have the same checksum, only in read mode"""
if self is other:
return True
return self.mode == "rb" and other.mode == "rb" and hash(self) == hash(other)
return (
isinstance(other, type(self))
and self.mode == "rb"
and other.mode == "rb"
and hash(self) == hash(other)
)

def commit(self):
"""Move from temp to final destination"""
Expand Down
4 changes: 4 additions & 0 deletions fsspec/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ def test_eq():
result = fs == 1
assert result is False

f = AbstractBufferedFile(fs, "misc/foo.txt", cache_type="bytes")
result = f == 1
assert result is False


def test_pickle_multiple():
a = DummyTestFS(1)
Expand Down

0 comments on commit df65747

Please sign in to comment.