Singleton¶
-
class
properties.extras.
Singleton
(name, **kwargs)[source]¶ Class that only allows one instance for each identifying name
These instances are stored on the
_SINGLETONS
attribute 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.
-
classmethod
deserialize
(value, trusted=False, strict=False, assert_valid=False, **kwargs)[source]¶ 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.
Note
If property values differ from the existing singleton and the input dictionary, the new values from the input dictionary will be ignored
-
classmethod