edgegraph.structure.singleton.check_semi_singleton_entry_exists

edgegraph.structure.singleton.check_semi_singleton_entry_exists#

edgegraph.structure.singleton.check_semi_singleton_entry_exists(cls, *args, **kwargs)#

Test whether a semisingleton exists for the given mapping without creating it.

This function allows checking whether a semisingleton instance exists for the provided identifier, without creating it if it does not exist.

>>> from edgegraph.singleton import semi_singleton_metaclass, \\
        check_semi_singleton_entry_exists
>>> class SemiSingleton(metaclass=semi_singleton_metaclass()):
...     def __init__(self, foo, bar=False):
...         self.foo = foo
...         self.bar = bar
...
>>> s3 = SemiSingleton(37, True)  # different arguments -- different object
>>> s3
<__main__.SemiSingleton object at 0x01234567>
>>> # object exists; it will be returned, but unaffected
>>> check_semi_singleton_entry_exists(SemiSingleton, 37, bar=True)
<__main__.SemiSingleton object at 0x01234567>
>>> # object does not exist; None returned, such an object is *not* created
>>> check_semi_singleton_entry_exists(128)
>>>
Parameters:
  • cls (type) – Class to test. This is typically thought of as type(some_object).

  • *args – Positional arguments as would normally be passed to the semi-singleton class instantiation.

  • **kwargs – Positional arguments as would normally be passed to the semi-singleton class instantiation.

Returns:

The instance accessible via the given mapping if such exists; else None.

Return type:

object