Skip to content

Commit

Permalink
fix type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
yanchengnv committed Sep 13, 2023
1 parent e5b7d89 commit ee06287
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions nvflare/apis/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StorageSpec(ABC):
"""

@abstractmethod
def create_object(self, uri: str, data: Union[bytes, str], meta: dict, overwrite_existing: bool):
def create_object(self, uri: str, data, meta: dict, overwrite_existing: bool):
"""Creates an object.
Examples of URI:
Expand All @@ -66,7 +66,7 @@ def create_object(self, uri: str, data: Union[bytes, str], meta: dict, overwrite
pass

@abstractmethod
def update_object(self, uri: str, data: Union[bytes, str], component_name: str):
def update_object(self, uri: str, data, component_name: str):
"""Update the object
Args:
Expand Down
4 changes: 2 additions & 2 deletions nvflare/app_common/storages/filesystem_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _save_data(self, data: Union[str, bytes], destination: str):
else:
raise ValueError(f"expect data to be bytes or file name but got {type(data)}")

def create_object(self, uri: str, data: Union[bytes, str], meta: dict, overwrite_existing: bool = False):
def create_object(self, uri: str, data, meta: dict, overwrite_existing: bool = False):
"""Creates an object.
Args:
Expand Down Expand Up @@ -134,7 +134,7 @@ def create_object(self, uri: str, data: Union[bytes, str], meta: dict, overwrite

return full_uri

def update_object(self, uri: str, data: Union[bytes, str], component_name: str = DATA):
def update_object(self, uri: str, data, component_name: str = DATA):
"""Update the object
Args:
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_test/app_common/storages/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def test_large_storage(self, storage, n_folders, n_files, path_depth):
"uri, data, meta, overwrite_existing",
[
(1234, b"c", {}, True),
("/test_dir/test_object", "not a byte string", {}, True),
("/test_dir/test_object", "not a valid file name", {}, True),
("/test_dir/test_object", b"c", "not a dictionary", True),
("/test_dir/test_object", b"c", {}, "not a bool"),
],
)
def test_create_invalid_inputs(self, storage, uri, data, meta, overwrite_existing):
with pytest.raises(TypeError):
with pytest.raises(Exception):
storage.create_object(uri, data, meta, overwrite_existing)

def test_invalid_inputs(self, storage):
Expand Down Expand Up @@ -161,12 +161,12 @@ def test_update_meta_invalid_inputs(self, storage, uri, meta, overwrite_existing
@pytest.mark.parametrize(
"uri, data",
[
(1234, "not bytes"),
(1234, "not valid file"),
("/test_dir/test_object", "not bytes"),
],
)
def test_update_data_invalid_inputs(self, storage, uri, data):
with pytest.raises(TypeError):
with pytest.raises(Exception):
storage.update_object(uri, data)

@pytest.mark.parametrize(
Expand Down

0 comments on commit ee06287

Please sign in to comment.