Skip to content

Commit

Permalink
feat: add generic in SingleInstanceMetaClass
Browse files Browse the repository at this point in the history
  • Loading branch information
csy1204 committed Jul 14, 2024
1 parent 6625af7 commit bf45f44
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pymilvus/orm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +31,8 @@

VIRTUAL_PORT = 443

T = TypeVar("T")


def synchronized(func: Callable):
"""
Expand All @@ -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)
Expand Down

0 comments on commit bf45f44

Please sign in to comment.