From 8017ae825b7c4cc3913971fab5308b172370d335 Mon Sep 17 00:00:00 2001 From: Grantham Taylor <54340816+granthamtaylor@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:29:01 -0400 Subject: [PATCH] add hash method to flytefile to fix bug in interactive shell (#2853) --- flytekit/types/file/file.py | 3 +++ tests/flytekit/unit/types/file/test_types.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index a76e5f4e05..a087af11eb 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -372,6 +372,9 @@ def __repr__(self): def __str__(self): return self.path + def __hash__(self): + return hash(str(self.path)) + class FlyteFilePathTransformer(AsyncTypeTransformer[FlyteFile]): def __init__(self): diff --git a/tests/flytekit/unit/types/file/test_types.py b/tests/flytekit/unit/types/file/test_types.py index cc3e575428..d1f4963a56 100644 --- a/tests/flytekit/unit/types/file/test_types.py +++ b/tests/flytekit/unit/types/file/test_types.py @@ -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)