diff --git a/pymilvus/orm/connections.py b/pymilvus/orm/connections.py index 490d7768c..7f53a6cfa 100644 --- a/pymilvus/orm/connections.py +++ b/pymilvus/orm/connections.py @@ -15,7 +15,7 @@ import pathlib import threading import time -from typing import Callable, Tuple, Union +from typing import Callable, Generic, Tuple, TypeVar, Union from urllib import parse from pymilvus.client.check import is_legal_address, is_legal_host, is_legal_port @@ -31,6 +31,8 @@ VIRTUAL_PORT = 443 +T = TypeVar("T") + def synchronized(func: Callable): """ @@ -45,13 +47,13 @@ def lock_func(*args, **kwargs): return lock_func -class SingleInstanceMetaClass(type): +class SingleInstanceMetaClass(Generic[T]): instance = None def __init__(cls, *args, **kwargs) -> None: super().__init__(*args, **kwargs) - def __call__(cls, *args, **kwargs): + def __call__(cls, *args, **kwargs) -> T: if cls.instance: return cls.instance cls.instance = cls.__new__(cls)