Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: add SingleInstanceMetaClass to inherit from a generic type #2176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading