Class that only allows one instance for each identifying name
These instances are stored on the
_SINGLETONSattribute of the class. You may create a new registry of singletons by redefining this attribute on a subclass. Also, this means multiple singleton classes may be present on a registry, therefore the class you use to access the singleton may not be the class of the returned singleton.
Each singleton must be initialized with a name. You can type-check and validate this value by including a ‘name’ property on your class. The identifying name does not change during the lifetime of the singleton, even if the ‘name’ value is changed.
deserialize(value, trusted=False, strict=False, assert_valid=False, **kwargs)¶
Create a Singleton instance from a serialized dictionary.
This behaves identically to HasProperties.deserialize, except if the singleton is already found in the singleton registry the existing value is used.
If property values differ from the existing singleton and the input dictionary, the new values from the input dictionary will be ignored
serialize(include_class=True, save_dynamic=False, **kwargs)¶
Serialize Singleton instance to a dictionary.
This behaves identically to HasProperties.serialize, except it also saves the identifying name in the dictionary as well.
Metaclass to produce singleton behavior using a singleton registry