class_docstr: Metaclass providing an implementation of the flyweight pattern.
  
  Since the flyweight is very similar to a singleton, we occasionally use this
  term to make clear there's only one instance (at a time).
  This integrates the "factory" into the actual classes, which need
  to have a class attribute `_unique_instances` (WeakValueDictionary).
  By providing an implementation of __call__, you don't need to call a
  factory's get_xy_repo() method to get a singleton. Instead this is called
  when you simply instantiate via MyClass(). So, you basically don't even need
  to know there were singletons. Therefore it is also less likely to sabotage
  the concept by not being aware of how to get an appropriate object.
  
  Multiple instances, pointing to the same physical repository can cause a
  lot of trouble. This is why this class exists. You should be very aware of
  the implications, if you want to circumvent that mechanism.
  
  To use this pattern, you need to add this class as a metaclass to the class
  you want to use it with. Additionally there needs to be a class attribute
  `_unique_instances`, which should be a `WeakValueDictionary`. Furthermore
  implement `_flyweight_id_from_args` method to determine, what should be the
  identifying criteria to consider two requested instances the same.
  
  Example:
  
  from weakref import WeakValueDictionary
  
  class MyFlyweightClass(object, metaclass=Flyweight):
  
      _unique_instances = WeakValueDictionary()
  
      @classmethod
      def _flyweight_id_from_args(cls, *args, **kwargs):
  
          id = kwargs.pop('id')
          return id, args, kwargs
  
      def __init__(self, some, someother=None):
          pass
  
  a = MyFlyweightClass('bla', id=1)
  b = MyFlyweightClass('blubb', id=1)
  assert a is b
  c = MyFlyweightClass('whatever', id=2)
  assert c is not a
class_docstr_tok: ["Metaclass","providing","an","implementation","of","the","flyweight","pattern",".","Since","the","flyweight","is","very","similar","to","a","singleton",",","we","occasionally","use","this","term","to","make","clear","there","'s","only","one","instance","(","at","a","time",")",".","This","integrates","the","``","factory","''","into","the","actual","classes",",","which","need","to","have","a","class","attribute","`","_unique_instances","`","(","WeakValueDictionary",")",".","By","providing","an","implementation","of","__call__",",","you","do","n't","need","to","call","a","factory","'s","get_xy_repo","(",")","method","to","get","a","singleton",".","Instead","this","is","called","when","you","simply","instantiate","via","MyClass","(",")",".","So",",","you","basically","do","n't","even","need","to","know","there","were","singletons",".","Therefore","it","is","also","less","likely","to","sabotage","the","concept","by","not","being","aware","of","how","to","get","an","appropriate","object",".","Multiple","instances",",","pointing","to","the","same","physical","repository","can","cause","a","lot","of","trouble",".","This","is","why","this","class","exists",".","You","should","be","very","aware","of","the","implications",",","if","you","want","to","circumvent","that","mechanism",".","To","use","this","pattern",",","you","need","to","add","this","class","as","a","metaclass","to","the","class","you","want","to","use","it","with",".","Additionally","there","needs","to","be","a","class","attribute","`","_unique_instances","`",",","which","should","be","a","`","WeakValueDictionary","`",".","Furthermore","implement","`","_flyweight_id_from_args","`","method","to","determine",",","what","should","be","the","identifying","criteria","to","consider","two","requested","instances","the","same",".","Example",":","from","weakref","import","WeakValueDictionary","class","MyFlyweightClass","(","object",",","metaclass=Flyweight",")",":","_unique_instances","=","WeakValueDictionary","(",")","@","classmethod","def","_flyweight_id_from_args","(","cls",",","*","args",",","*","*","kwargs",")",":","id","=","kwargs.pop","(","'id","'",")","return","id",",","args",",","kwargs","def","__init__","(","self",",","some",",","someother=None",")",":","pass","a","=","MyFlyweightClass","(","'bla","'",",","id=1",")","b","=","MyFlyweightClass","(","'blubb","'",",","id=1",")","assert","a","is","b","c","=","MyFlyweightClass","(","'whatever","'",",","id=2",")","assert","c","is","not","a"]
docstr: create an ID from arguments passed to `__call__`
  
  Subclasses need to implement this method. The ID it returns is used to
  determine whether or not there already is an instance of that kind and
  as key in the `_unique_instances` dictionary.
  
  Besides the ID this should return args and kwargs, which can be modified
  herein and will be passed on to the constructor of a requested instance.
  
  Parameters
  ----------
  args:
   positional arguments passed to __call__
  kwargs:
   keyword arguments passed to __call__
  
  Returns
  -------
  hashable, args, kwargs
    id, optionally manipulated args and kwargs to be passed to __init__
docstr_tok: ["create","an","ID","from","arguments","passed","to","`","__call__","`","Subclasses","need","to","implement","this","method",".","The","ID","it","returns","is","used","to","determine","whether","or","not","there","already","is","an","instance","of","that","kind","and","as","key","in","the","`","_unique_instances","`","dictionary",".","Besides","the","ID","this","should","return","args","and","kwargs",",","which","can","be","modified","herein","and","will","be","passed","on","to","the","constructor","of","a","requested","instance",".","Parameters","--","--","--","--","--","args",":","positional","arguments","passed","to","__call__","kwargs",":","keyword","arguments","passed","to","__call__","Returns","--","--","--","-","hashable",",","args",",","kwargs","id",",","optionally","manipulated","args","and","kwargs","to","be","passed","to","__init__"]
code: def _flyweight_id_from_args(cls, *args, **kwargs):
      """create an ID from arguments passed to `__call__`
  
      Subclasses need to implement this method. The ID it returns is used to
      determine whether or not there already is an instance of that kind and
      as key in the `_unique_instances` dictionary.
  
      Besides the ID this should return args and kwargs, which can be modified
      herein and will be passed on to the constructor of a requested instance.
  
      Parameters
      ----------
      args:
       positional arguments passed to __call__
      kwargs:
       keyword arguments passed to __call__
  
      Returns
      -------
      hashable, args, kwargs
        id, optionally manipulated args and kwargs to be passed to __init__
      """
      raise NotImplementedError
  
file_path: datalad/datalad/dataset/repo.py
imports: import logging
  import threading
  from datalad.support.exceptions import InvalidInstanceRequestError
  from datalad.support.network import RI
  from datalad import utils
label_desc: Use image node_id 1 for calling the Flyweight obj's underlying member method code with example usage: obj._flyweight_id_from_args(cls) without return types