edgegraph.structure.singleton.clear_semi_singleton

edgegraph.structure.singleton.clear_semi_singleton#

edgegraph.structure.singleton.clear_semi_singleton(cls)#

Clears a specified semi-singleton.

This operation is also sometimes referred to as “resetting” a (semi-)singleton data type. It clears the internal hashmap (dictionary) relating hashed arguments to their instance. It may be best explained by example:

>>> from edgegraph.structure import singleton
>>> class SemiSingle(metaclass=singleton.semi_singleton_metaclass()): pass
>>> instances = [SemiSingle(i) for i in range(10)]  # all unique instances
>>> s = SemiSingle(7)
>>> s is instances[7]
True
>>> singleton.clear_semi_singleton(SemiSingle)
>>> s2 = SemiSingle(7)  # will now give us a new object
>>> s is s2  # see, different from the old one!
False

Note that this operation does not outright delete all the old objects. Normal garbage collection rules apply.

See also

Parameters:

cls (type) – Class to clear semisingleton states from.