Skip to content

Commit 83d358f

Browse files
authored
[misc] Adding Generic Types for IDE (#1063)
1 parent a5f188f commit 83d358f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lightllm/models/registry.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
logger = init_logger(__name__)
55

66
from dataclasses import dataclass
7-
from typing import Type, Dict, Optional, Callable, List, Union
7+
from typing import Type, Dict, Optional, Callable, List, Union, TypeVar
88
from lightllm.utils.log_utils import init_logger
99

1010
logger = init_logger(__name__)
1111

12+
# 定义泛型类型变量,用于保持输入和输出类型的一致性
13+
T = TypeVar("T")
14+
1215

1316
@dataclass
1417
class ModelConfig:
@@ -26,12 +29,12 @@ def __call__(
2629
model_type: Union[str, List[str]],
2730
is_multimodal: bool = False,
2831
condition: Optional[Callable[[dict], bool]] = None,
29-
):
32+
) -> Callable[[T], T]:
3033
"""Decorator to register a model (now more concise)."""
3134

3235
def decorator(
33-
model_class: Type,
34-
):
36+
model_class: T,
37+
) -> T:
3538
model_types = [model_type] if isinstance(model_type, str) else model_type
3639
for mt in model_types:
3740
self._registry[mt].append(

0 commit comments

Comments
 (0)