class_docstr: A configurable that only allows one instance.
  
  This class is for classes that should only have one instance of itself
  or *any* subclass. To create and retrieve such a class use the
  :meth:`SingletonConfigurable.instance` method.
docstr: Returns a global instance of this class.
  
  This method create a new instance if none have previously been created
  and returns a previously created instance is one already exists.
  
  The arguments and keyword arguments passed to this method are passed
  on to the :meth:`__init__` method of the class upon instantiation.
  
  Examples
  --------
  Create a singleton class using instance, and retrieve it::
  
      >>> from traitlets.config.configurable import SingletonConfigurable
      >>> class Foo(SingletonConfigurable): pass
      >>> foo = Foo.instance()
      >>> foo == Foo.instance()
      True
  
  Create a subclass that is retrieved using the base class instance::
  
      >>> class Bar(SingletonConfigurable): pass
      >>> class Bam(Bar): pass
      >>> bam = Bam.instance()
      >>> bam == Bar.instance()
      True
code: def instance(cls: type[CT], *args: t.Any, **kwargs: t.Any) -> CT:
      """Returns a global instance of this class.
  
      This method create a new instance if none have previously been created
      and returns a previously created instance is one already exists.
  
      The arguments and keyword arguments passed to this method are passed
      on to the :meth:`__init__` method of the class upon instantiation.
  
      Examples
      --------
      Create a singleton class using instance, and retrieve it::
  
          >>> from traitlets.config.configurable import SingletonConfigurable
          >>> class Foo(SingletonConfigurable): pass
          >>> foo = Foo.instance()
          >>> foo == Foo.instance()
          True
  
      Create a subclass that is retrieved using the base class instance::
  
          >>> class Bar(SingletonConfigurable): pass
          >>> class Bam(Bar): pass
          >>> bam = Bam.instance()
          >>> bam == Bar.instance()
          True
      """
      # Create and save the instance
      if cls._instance is None:
          inst = cls(*args, **kwargs)
          # Now make sure that the instance will also be returned by
          # parent classes' _instance attribute.
          for subclass in cls._walk_mro():
              subclass._instance = inst
  
      if isinstance(cls._instance, cls):
          return cls._instance
      else:
          raise MultipleInstanceError(
              f"An incompatible sibling of '{cls.__name__}' is already instantiated"
              f" as singleton: {type(cls._instance).__name__}"
          )
  
imports: from __future__ import annotations
  import logging
  import typing
  from copy import deepcopy
  from textwrap import dedent
  from traitlets.traitlets import Any, Container, Dict, HasTraits, Instance, TraitType, default, observe, observe_compat, validate
  from traitlets.utils import warnings
  from traitlets.utils.bunch import Bunch
  from traitlets.utils.text import indent, wrap_paragraphs
  from .loader import Config, DeferredConfig, LazyConfigValue, _is_section_key
label_desc: Use image node_id 3 for calling the SingletonConfigurable obj's underlying member method code with example usage: obj.instance(cls) and returns: cls