Shortcuts

Source code for ding.utils.design_helper

from abc import ABCMeta


# ABCMeta is a subclass of type, extending ABCMeta makes this metaclass is compatible with some classes
# which extends ABC
[docs]class SingletonMetaclass(ABCMeta): """ Overview: Returns the given type instance in input class Interfaces: ``__call__`` """ instances = {} def __call__(cls: type, *args, **kwargs) -> object: """ Overview: Returns the given type instance in input class """ if cls not in SingletonMetaclass.instances: SingletonMetaclass.instances[cls] = super(SingletonMetaclass, cls).__call__(*args, **kwargs) cls.instance = SingletonMetaclass.instances[cls] return SingletonMetaclass.instances[cls]

© Copyright 2021, OpenDILab Contributors. Revision ae2e42a4.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.