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

add __hash__ method to FlyteFile to fix bug during interactive mode #2853

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flytekit/types/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
def __str__(self):
return self.path

def __hash__(self):
return hash(str(self.path))

Check warning on line 376 in flytekit/types/file/file.py

View check run for this annotation

Codecov / codecov/patch

flytekit/types/file/file.py#L376

Added line #L376 was not covered by tests


class FlyteFilePathTransformer(AsyncTypeTransformer[FlyteFile]):
def __init__(self):
Expand Down
9 changes: 9 additions & 0 deletions tests/flytekit/unit/types/file/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ def test_new_auto_file():
ff = FlyteFile.new("my-file.txt")
cwd = FlyteContextManager.current_context().user_space_params.working_directory
assert cwd in ff.path

def test_file_is_hashable():

ff1 = FlyteFile.new("file1.txt")
ff2 = FlyteFile.new("file2.txt")

assert isinstance({ff1, ff2}, set)

assert isinstance(hash(ff1), int)
Loading