edgegraph.structure.singleton.clear_true_singleton#
- edgegraph.structure.singleton.clear_true_singleton(cls=None)#
Clear TrueSingleton cache for either a specified type, or all TrueSingleton types.
This operation is also sometimes referred to as “resetting” a singleton data type. It removes the reference to the single object that would otherwise be returned.
After calling this function, the next instantiation attempt on the given singleton type will result in an actual re-creation and instantiation of a new object. For example:
>>> from edgegraph.structure import singleton >>> class S(metaclass=singleton.TrueSingleton): pass >>> s1 = S() >>> s2 = S() >>> s1 is s2 True >>> singleton.clear_true_singleton(S) >>> s3 = S() >>> s4 = S() >>> s2 is s3 False >>> s3 is s4 True
Note that this can also be used to clear all TrueSingleton objects by leaving the
clsparameter empty:>>> from edgegraph.structure import singleton >>> class S(metaclass=singleton.TrueSingleton): pass >>> class S(metaclass=singleton.TrueSingleton): pass >>> s1 = S() >>> s2 = S() >>> s1 is s2 True >>> r1 = R() >>> r2 = R() >>> r1 is r2 True >>> singleton.clear_true_singleton() # no argument used here >>> s3 = S() >>> s2 is s3 False >>> r3 = R() >>> r2 is r3 False
- Parameters:
cls (type | None) – The data type to clear singleton references from. If not specified, clears all TrueSingleton types.