From da5477bdbf25c2eec11f8a8bf5a1b1ab5f6d2689 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Fri, 25 Apr 2025 14:07:17 +0300 Subject: [PATCH] Apply no-implicit-optional fixes --- src/mflux/models/depth_pro/feature_fusion_block_2d.py | 2 +- src/mflux/models/depth_pro/upsample_block.py | 2 +- src/mflux/post_processing/generated_image.py | 3 +-- src/mflux/post_processing/image_util.py | 9 ++++----- src/mflux/weights/weight_handler_lora_huggingface.py | 8 ++++---- .../helpers/image_generation_depth_test_helper.py | 4 ++-- .../helpers/image_generation_in_context_test_helper.py | 4 ++-- .../helpers/image_generation_test_helper.py | 4 ++-- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/mflux/models/depth_pro/feature_fusion_block_2d.py b/src/mflux/models/depth_pro/feature_fusion_block_2d.py index ae6b6c5..db500d3 100644 --- a/src/mflux/models/depth_pro/feature_fusion_block_2d.py +++ b/src/mflux/models/depth_pro/feature_fusion_block_2d.py @@ -14,7 +14,7 @@ class FeatureFusionBlock2d(nn.Module): self.deconv = nn.ConvTranspose2d(in_channels=num_features, out_channels=num_features, kernel_size=2, stride=2, padding=0, bias=False) # fmt: off self.out_conv = nn.Conv2d(in_channels=num_features, out_channels=num_features, kernel_size=1, stride=1, padding=0, bias=True) # fmt: off - def __call__(self, x0: mx.array, x1: mx.array = None) -> mx.array: + def __call__(self, x0: mx.array, x1: mx.array | None = None) -> mx.array: x = x0 if x1 is not None: res = self.resnet1(x1) diff --git a/src/mflux/models/depth_pro/upsample_block.py b/src/mflux/models/depth_pro/upsample_block.py index 3e81c99..ae647cd 100644 --- a/src/mflux/models/depth_pro/upsample_block.py +++ b/src/mflux/models/depth_pro/upsample_block.py @@ -21,7 +21,7 @@ class UpSampleBlock(nn.Module): ) # fmt: off @staticmethod - def _create_layers(dim_in: int, dim_out: int, upsample_layers: int, dim_int: int = None) -> list[nn.Module]: + def _create_layers(dim_in: int, dim_out: int, upsample_layers: int, dim_int: int | None = None) -> list[nn.Module]: if dim_int is None: dim_int = dim_out diff --git a/src/mflux/post_processing/generated_image.py b/src/mflux/post_processing/generated_image.py index 1eea9cb..8232d0f 100644 --- a/src/mflux/post_processing/generated_image.py +++ b/src/mflux/post_processing/generated_image.py @@ -1,5 +1,4 @@ import importlib -import typing as t from pathlib import Path import mlx.core as mx @@ -78,7 +77,7 @@ class GeneratedImage: def save( self, - path: t.Union[str, Path], + path: str | Path, export_json_metadata: bool = False, overwrite: bool = False, ) -> None: diff --git a/src/mflux/post_processing/image_util.py b/src/mflux/post_processing/image_util.py index 997579d..b7b013a 100644 --- a/src/mflux/post_processing/image_util.py +++ b/src/mflux/post_processing/image_util.py @@ -1,6 +1,5 @@ import json import logging -import typing as t from pathlib import Path import mlx.core as mx @@ -59,7 +58,7 @@ class ImageUtil: ) @staticmethod - def to_composite_image(generated_images: t.List[GeneratedImage]) -> PIL.Image.Image: + def to_composite_image(generated_images: list[GeneratedImage]) -> PIL.Image.Image: # stitch horizontally total_width = sum(gen_img.image.width for gen_img in generated_images) max_height = max(gen_img.image.height for gen_img in generated_images) @@ -119,7 +118,7 @@ class ImageUtil: @staticmethod def expand_image( image: PIL.Image.Image, - box_values: AbsoluteBoxValues = None, + box_values: AbsoluteBoxValues | None = None, top: int | str = 0, right: int | str = 0, bottom: int | str = 0, @@ -161,7 +160,7 @@ class ImageUtil: orig_height: int, border_color: tuple, content_color: tuple, - box_values: AbsoluteBoxValues = None, + box_values: AbsoluteBoxValues | None = None, top: int | str = 0, right: int | str = 0, bottom: int | str = 0, @@ -204,7 +203,7 @@ class ImageUtil: @staticmethod def save_image( image: PIL.Image.Image, - path: t.Union[str, Path], + path: str | Path, metadata: dict | None = None, export_json_metadata: bool = False, overwrite: bool = False, diff --git a/src/mflux/weights/weight_handler_lora_huggingface.py b/src/mflux/weights/weight_handler_lora_huggingface.py index fe270c5..b5be70d 100644 --- a/src/mflux/weights/weight_handler_lora_huggingface.py +++ b/src/mflux/weights/weight_handler_lora_huggingface.py @@ -7,9 +7,9 @@ from huggingface_hub import snapshot_download class WeightHandlerLoRAHuggingFace: @staticmethod def download_loras( - lora_names: list[str] = None, - repo_id: str = None, - cache_dir: str = None, + lora_names: list[str] | None = None, + repo_id: str | None = None, + cache_dir: str | None = None, ) -> list[str]: if repo_id is None: return [] @@ -30,7 +30,7 @@ class WeightHandlerLoRAHuggingFace: def _download_lora( repo_id: str, lora_name: str, - cache_dir: str = None, + cache_dir: str | None = None, ) -> str: # Create cache directory if it doesn't exist if cache_dir is None: diff --git a/tests/image_generation/helpers/image_generation_depth_test_helper.py b/tests/image_generation/helpers/image_generation_depth_test_helper.py index 68b7ff1..af275d4 100644 --- a/tests/image_generation/helpers/image_generation_depth_test_helper.py +++ b/tests/image_generation/helpers/image_generation_depth_test_helper.py @@ -17,8 +17,8 @@ class ImageGeneratorDepthTestHelper: prompt: str, steps: int, seed: int, - height: int = None, - width: int = None, + height: int | None = None, + width: int | None = None, image_path: str | None = None, depth_image_path: str | None = None, ): diff --git a/tests/image_generation/helpers/image_generation_in_context_test_helper.py b/tests/image_generation/helpers/image_generation_in_context_test_helper.py index 08712bd..17bd3e9 100644 --- a/tests/image_generation/helpers/image_generation_in_context_test_helper.py +++ b/tests/image_generation/helpers/image_generation_in_context_test_helper.py @@ -18,8 +18,8 @@ class ImageGeneratorInContextTestHelper: prompt: str, steps: int, seed: int, - height: int = None, - width: int = None, + height: int | None = None, + width: int | None = None, image_path: str | None = None, lora_style: str | None = None, lora_paths: list[str] | None = None, diff --git a/tests/image_generation/helpers/image_generation_test_helper.py b/tests/image_generation/helpers/image_generation_test_helper.py index 6af307c..414be74 100644 --- a/tests/image_generation/helpers/image_generation_test_helper.py +++ b/tests/image_generation/helpers/image_generation_test_helper.py @@ -16,8 +16,8 @@ class ImageGeneratorTestHelper: prompt: str, steps: int, seed: int, - height: int = None, - width: int = None, + height: int | None = None, + width: int | None = None, image_path: str | None = None, image_strength: float | None = None, lora_paths: list[str] | None = None,