Skip to content

Commit

Permalink
Annotate some functions that return None
Browse files Browse the repository at this point in the history
Summary: Test functions return None. This codemod fixes that so type annotation efforts can focus on trickier cases.

Reviewed By: azad-meta

Differential Revision: D52570249

fbshipit-source-id: 6ea7be3e707ce5dfdf5a900e959459deebe1eff6
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 5, 2024
1 parent a5a678c commit e7d4fbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions test/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def _convert_to_tensor(data):


class TestIterDataPipeSerialization(expecttest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.temp_dir = create_temp_dir()
self.temp_files = create_temp_files(self.temp_dir)
self.temp_sub_dir = create_temp_dir(self.temp_dir.name)
self.temp_sub_files = create_temp_files(self.temp_sub_dir, 4, False)

def tearDown(self):
def tearDown(self) -> None:
try:
self.temp_sub_dir.cleanup()
self.temp_dir.cleanup()
Expand Down Expand Up @@ -168,7 +168,7 @@ def _serialization_test_for_dp_with_children(self, dp1, dp2, use_dill):
self._serialization_test_helper(dp1, use_dill=use_dill)
self._serialization_test_helper(dp2, use_dill=use_dill)

def test_serializable(self):
def test_serializable(self) -> None:
# A tuple of 4 objects
# (DataPipeConstructor, custom_input_datapipe=None, dp_args=(), dp_kwargs={})
picklable_datapipes: List = [
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_serializable(self):
print(f"{dpipe} is failing.")
raise e

def test_serializable_with_dill(self):
def test_serializable_with_dill(self) -> None:
"""Only for DataPipes that take in a function as argument"""
input_dp = IterableWrapper(range(10))
ref_idp = IterableWrapper(range(10))
Expand Down Expand Up @@ -416,7 +416,7 @@ def _serialization_test_for_dp_with_children(self, dp1, dp2):
self._serialization_test_helper(dp1)
self._serialization_test_helper(dp2)

def test_serializable(self):
def test_serializable(self) -> None:
picklable_datapipes: List = [
(mapdp.InMemoryCacheHolder, None, (), {}),
(mapdp.IterToMapConverter, IterableWrapper([(i, i) for i in range(10)]), (), {}),
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_serializable(self):
print(f"{dpipe} is failing.")
raise e

def test_serializable_with_dill(self):
def test_serializable_with_dill(self) -> None:
"""Only for DataPipes that take in a function as argument"""
pass

Expand Down
10 changes: 5 additions & 5 deletions test/test_tfrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class TestDataPipeTFRecord(expecttest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "_fakedata", "tfrecord")

def assertArrayEqual(self, arr1, arr2):
Expand All @@ -45,7 +45,7 @@ def assertArrayEqual(self, arr1, arr2):
arr2 = torch.stack(arr2)
torch.testing.assert_close(arr1, arr2, check_dtype=False)

def _ground_truth_data(self):
def _ground_truth_data(self) -> None:
for i in range(4):
x = torch.arange(i * 10, (i + 1) * 10)
yield {
Expand All @@ -54,7 +54,7 @@ def _ground_truth_data(self):
"x_byte": [b"test str"],
}

def _ground_truth_seq_data(self):
def _ground_truth_seq_data(self) -> None:
for i in range(4):
x = torch.arange(i * 10, (i + 1) * 10)
rep = 2 * i + 3
Expand All @@ -69,7 +69,7 @@ def _ground_truth_seq_data(self):
IS_M1, "Protobuf 3.19.* is not supported on MacOS M1, but Tensorflow is incompatible with Protobuf 4"
)
@torch.no_grad()
def test_tfrecord_loader_example_iterdatapipe(self):
def test_tfrecord_loader_example_iterdatapipe(self) -> None:
filename = f"{self.temp_dir}/example.tfrecord"
datapipe1 = IterableWrapper([filename])
datapipe2 = FileOpener(datapipe1, mode="b")
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_tfrecord_loader_example_iterdatapipe(self):
IS_M1, "Protobuf 3.19.* is not supported on MacOS M1, but Tensorflow is incompatible with Protobuf 4"
)
@torch.no_grad()
def test_tfrecord_loader_sequence_example_iterdatapipe(self):
def test_tfrecord_loader_sequence_example_iterdatapipe(self) -> None:
filename = f"{self.temp_dir}/sequence_example.tfrecord"
datapipe1 = IterableWrapper([filename])
datapipe2 = FileOpener(datapipe1, mode="b")
Expand Down

0 comments on commit e7d4fbe

Please sign in to comment.