fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -96,7 +96,7 @@ class ImageProcessor:
|
||||
"other": "其他",
|
||||
}
|
||||
|
||||
def __init__(self, temp_dir: str = None) -> None:
|
||||
def __init__(self, temp_dir: str | None = None) -> None:
|
||||
"""
|
||||
初始化图片处理器
|
||||
|
||||
@@ -106,7 +106,7 @@ class ImageProcessor:
|
||||
self.temp_dir = temp_dir or os.path.join(os.getcwd(), "temp", "images")
|
||||
os.makedirs(self.temp_dir, exist_ok=True)
|
||||
|
||||
def preprocess_image(self, image, image_type: str = None) -> None:
|
||||
def preprocess_image(self, image, image_type: str | None = None) -> None:
|
||||
"""
|
||||
预处理图片以提高OCR质量
|
||||
|
||||
@@ -328,7 +328,10 @@ class ImageProcessor:
|
||||
return unique_entities
|
||||
|
||||
def generate_description(
|
||||
self, image_type: str, ocr_text: str, entities: list[ImageEntity],
|
||||
self,
|
||||
image_type: str,
|
||||
ocr_text: str,
|
||||
entities: list[ImageEntity],
|
||||
) -> str:
|
||||
"""
|
||||
生成图片描述
|
||||
@@ -361,8 +364,8 @@ class ImageProcessor:
|
||||
def process_image(
|
||||
self,
|
||||
image_data: bytes,
|
||||
filename: str = None,
|
||||
image_id: str = None,
|
||||
filename: str | None = None,
|
||||
image_id: str | None = None,
|
||||
detect_type: bool = True,
|
||||
) -> ImageProcessingResult:
|
||||
"""
|
||||
@@ -487,7 +490,9 @@ class ImageProcessor:
|
||||
return relations
|
||||
|
||||
def process_batch(
|
||||
self, images_data: list[tuple[bytes, str]], project_id: str = None,
|
||||
self,
|
||||
images_data: list[tuple[bytes, str]],
|
||||
project_id: str | None = None,
|
||||
) -> BatchProcessingResult:
|
||||
"""
|
||||
批量处理图片
|
||||
@@ -561,7 +566,7 @@ class ImageProcessor:
|
||||
_image_processor = None
|
||||
|
||||
|
||||
def get_image_processor(temp_dir: str = None) -> ImageProcessor:
|
||||
def get_image_processor(temp_dir: str | None = None) -> ImageProcessor:
|
||||
"""获取图片处理器单例"""
|
||||
global _image_processor
|
||||
if _image_processor is None:
|
||||
|
||||
Reference in New Issue
Block a user