Skip to content

Commit 4dce0a5

Browse files
authored
fix: 修复_load_imgs中isinstance(img_content,InputType)错误
修复_load_imgs中isinstance(img_content,InputType)错误
2 parents 7656578 + c8a7c01 commit 4dce0a5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

rapid_table/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
from dataclasses import asdict
77
from pathlib import Path
8-
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
8+
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, get_args
99

1010
import numpy as np
1111
from tqdm import tqdm
@@ -75,6 +75,16 @@ def __call__(
7575
if not isinstance(img_contents, list):
7676
img_contents = [img_contents]
7777

78+
for img_content in img_contents:
79+
if not isinstance(img_content, get_args(InputType)):
80+
type_names = ", ".join([t.__name__ for t in get_args(InputType)])
81+
actual_type = (
82+
type(img_content).__name__ if img_content is not None else "None"
83+
)
84+
raise TypeError(
85+
f"Type Error: Expected input of type [{type_names}], but received '{img_content}' of type {actual_type}."
86+
)
87+
7888
s = time.perf_counter()
7989

8090
results = RapidTableOutput()
@@ -111,9 +121,7 @@ def __call__(
111121
def _load_imgs(
112122
self, img_content: Union[Sequence[InputType], InputType]
113123
) -> List[np.ndarray]:
114-
img_contents = (
115-
[img_content] if isinstance(img_content, InputType) else img_content
116-
)
124+
img_contents = img_content if isinstance(img_content, list) else [img_content]
117125
return [self.load_img(img) for img in img_contents]
118126

119127
def get_ocr_results(

0 commit comments

Comments
 (0)