From e345cbdfba9c656b01ef4e116822ad03ffe9d804 Mon Sep 17 00:00:00 2001 From: hertschuh <1091026+hertschuh@users.noreply.github.com> Date: Tue, 14 Jan 2025 19:23:00 -0800 Subject: [PATCH] Remove all type annotations for consistency. (#20762) Some tools don't like the mix of code with and without type hints. --- keras/src/backend/common/backend_utils.py | 2 +- keras/src/backend/common/dtypes_test.py | 2 +- keras/src/backend/common/variables_test.py | 2 +- keras/src/backend/torch/layer.py | 11 ++++------- .../bounding_boxes/bounding_box.py | 4 ++-- keras/src/ops/core_test.py | 2 +- keras/src/ops/image_test.py | 8 ++++---- keras/src/ops/math_test.py | 2 +- keras/src/ops/nn_test.py | 2 +- keras/src/ops/numpy_test.py | 2 +- keras/src/random/random_test.py | 2 +- keras/src/saving/saving_lib_test.py | 4 ++-- keras/src/visualization/draw_segmentation_masks.py | 2 +- keras/src/wrappers/sklearn_test.py | 4 ++-- keras/src/wrappers/sklearn_wrapper.py | 2 +- 15 files changed, 24 insertions(+), 27 deletions(-) diff --git a/keras/src/backend/common/backend_utils.py b/keras/src/backend/common/backend_utils.py index 7a4948c1b5f..fb809c2cc7b 100644 --- a/keras/src/backend/common/backend_utils.py +++ b/keras/src/backend/common/backend_utils.py @@ -356,7 +356,7 @@ def _vectorize_parse_input_dimensions( f"expected {len(input_core_dims)}, got {len(args)}" ) shapes = [] - dim_sizes: dict[str, int] = {} + dim_sizes = {} for arg, core_dims in zip(args, input_core_dims): _vectorize_update_dim_sizes( dim_sizes, arg.shape, core_dims, is_input=True diff --git a/keras/src/backend/common/dtypes_test.py b/keras/src/backend/common/dtypes_test.py index 82828d60042..7750dcecdd1 100644 --- a/keras/src/backend/common/dtypes_test.py +++ b/keras/src/backend/common/dtypes_test.py @@ -43,7 +43,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/backend/common/variables_test.py b/keras/src/backend/common/variables_test.py index 72b45465d7b..fe8e0f48bcf 100644 --- a/keras/src/backend/common/variables_test.py +++ b/keras/src/backend/common/variables_test.py @@ -820,7 +820,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/backend/torch/layer.py b/keras/src/backend/torch/layer.py index 04fb1043ad9..da05f32ddfb 100644 --- a/keras/src/backend/torch/layer.py +++ b/keras/src/backend/torch/layer.py @@ -1,6 +1,3 @@ -from typing import Iterator -from typing import Tuple - import torch from keras.src.backend.common.stateless_scope import in_stateless_scope @@ -30,10 +27,10 @@ def _track_variables(self): def named_parameters( self, - prefix: str = "", - recurse: bool = True, - remove_duplicate: bool = True, - ) -> Iterator[Tuple[str, torch.nn.Parameter]]: + prefix="", + recurse=True, + remove_duplicate=True, + ): if not hasattr(self, "_torch_params"): self._track_variables() return torch.nn.Module.named_parameters( diff --git a/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py b/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py index 08e41e31223..1c9515bd1f6 100644 --- a/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py +++ b/keras/src/layers/preprocessing/image_preprocessing/bounding_boxes/bounding_box.py @@ -22,8 +22,8 @@ def __init__(self): def convert_format( self, boxes, - source: str, - target: str, + source, + target, height=None, width=None, dtype="float32", diff --git a/keras/src/ops/core_test.py b/keras/src/ops/core_test.py index e4b220bf986..638ad933e50 100644 --- a/keras/src/ops/core_test.py +++ b/keras/src/ops/core_test.py @@ -936,7 +936,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/ops/image_test.py b/keras/src/ops/image_test.py index 22706989d16..e5115a988bc 100644 --- a/keras/src/ops/image_test.py +++ b/keras/src/ops/image_test.py @@ -20,7 +20,7 @@ def setUp(self): backend.set_image_data_format("channels_last") return super().setUp() - def tearDown(self) -> None: + def tearDown(self): backend.set_image_data_format(self.data_format) return super().tearDown() @@ -171,7 +171,7 @@ def setUp(self): backend.set_image_data_format("channels_last") return super().setUp() - def tearDown(self) -> None: + def tearDown(self): backend.set_image_data_format(self.data_format) return super().tearDown() @@ -396,7 +396,7 @@ def setUp(self): backend.set_image_data_format("channels_last") return super().setUp() - def tearDown(self) -> None: + def tearDown(self): backend.set_image_data_format(self.data_format) return super().tearDown() @@ -1144,7 +1144,7 @@ def setUp(self): backend.set_image_data_format("channels_last") return super().setUp() - def tearDown(self) -> None: + def tearDown(self): backend.set_image_data_format(self.data_format) return super().tearDown() diff --git a/keras/src/ops/math_test.py b/keras/src/ops/math_test.py index 4801bbb84af..5786827717d 100644 --- a/keras/src/ops/math_test.py +++ b/keras/src/ops/math_test.py @@ -1003,7 +1003,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/ops/nn_test.py b/keras/src/ops/nn_test.py index 8120a0ce803..c027e846ef0 100644 --- a/keras/src/ops/nn_test.py +++ b/keras/src/ops/nn_test.py @@ -2474,7 +2474,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/ops/numpy_test.py b/keras/src/ops/numpy_test.py index 08869d1ccc6..9bd9f480056 100644 --- a/keras/src/ops/numpy_test.py +++ b/keras/src/ops/numpy_test.py @@ -5357,7 +5357,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/random/random_test.py b/keras/src/random/random_test.py index e8b40483b27..9e78b8748b4 100644 --- a/keras/src/random/random_test.py +++ b/keras/src/random/random_test.py @@ -456,7 +456,7 @@ def setUp(self): self.jax_enable_x64.__enter__() return super().setUp() - def tearDown(self) -> None: + def tearDown(self): if backend.backend() == "jax": self.jax_enable_x64.__exit__(None, None, None) return super().tearDown() diff --git a/keras/src/saving/saving_lib_test.py b/keras/src/saving/saving_lib_test.py index 1cfaad935ba..f72a9a606a4 100644 --- a/keras/src/saving/saving_lib_test.py +++ b/keras/src/saving/saving_lib_test.py @@ -253,7 +253,7 @@ def setUp(self): saving_lib._MEMORY_UPPER_BOUND = 0 return super().setUp() - def tearDown(self) -> None: + def tearDown(self): saving_lib._MEMORY_UPPER_BOUND = self.original_value return super().tearDown() @@ -621,7 +621,7 @@ def test_partial_load(self): ) @pytest.mark.requires_trainable_backend - def test_save_to_fileobj(self) -> None: + def test_save_to_fileobj(self): model = keras.Sequential( [keras.layers.Dense(1, input_shape=(1,)), keras.layers.Dense(1)] ) diff --git a/keras/src/visualization/draw_segmentation_masks.py b/keras/src/visualization/draw_segmentation_masks.py index 99689778d99..0fa8c6fbb7a 100644 --- a/keras/src/visualization/draw_segmentation_masks.py +++ b/keras/src/visualization/draw_segmentation_masks.py @@ -104,6 +104,6 @@ def draw_segmentation_masks( return outputs -def _generate_color_palette(num_classes: int): +def _generate_color_palette(num_classes): palette = np.array([2**25 - 1, 2**15 - 1, 2**21 - 1]) return [((i * palette) % 255).tolist() for i in range(num_classes)] diff --git a/keras/src/wrappers/sklearn_test.py b/keras/src/wrappers/sklearn_test.py index 8a644d28796..250b12c5127 100644 --- a/keras/src/wrappers/sklearn_test.py +++ b/keras/src/wrappers/sklearn_test.py @@ -21,7 +21,7 @@ def wrapped_parametrize_with_checks( estimators, *, - legacy: bool = True, + legacy=True, expected_failed_checks=None, ): """Wrapped `parametrize_with_checks` handling backwards compat.""" @@ -77,7 +77,7 @@ def dynamic_model(X, y, loss, layers=[10]): @contextmanager -def use_floatx(x: str): +def use_floatx(x): """Context manager to temporarily set the keras backend precision. """ diff --git a/keras/src/wrappers/sklearn_wrapper.py b/keras/src/wrappers/sklearn_wrapper.py index 4437014da2e..77c3488b6ee 100644 --- a/keras/src/wrappers/sklearn_wrapper.py +++ b/keras/src/wrappers/sklearn_wrapper.py @@ -107,7 +107,7 @@ def __sklearn_clone__(self): ) @property - def epoch_(self) -> int: + def epoch_(self): """The current training epoch.""" return getattr(self, "history_", {}).get("epoch", 0)