The FrozenState class is used to provide immutable versions of State instances.
Why would you want this? On their own, State instances don't support hashing, since they're generally mutable.
The solution is FrozenState: immutable, hashable versions of State instances.
-
The
FrozenState()constructor takes three arguments, the last of which is optional.-
cls - the class of the State being frozen. This should be an instance of the
classortypetype. -
state - an object representing the internal state of the State instance being frozen.
-
thawer - optional. If specified, this should be a function that will be used to thaw (aka, "unfreeze") the
FrozenStateinstance. When invoked, this function will be passed two parameters: first, the type of the State being thawed (theclsparameter); second, the internal state of the to-be-unfrozen State (thestateparameter).If this is left unspecified or is
None, it assumed that theclsclass defines defines a_thawclassmethod.
-
-
FrozenStatedefines afreezemethod. This merely returns the invocant. -
FrozenStatedefines athawmethod. This is used to thaw -- or "unfreeze" -- the State instance represented in the invocant.thawreturns an instance of the State class. The returnedStateinstance will be a deep copy of the instance that was originally frozen. -
FrozenStateinstances that were created with the sameclsandstateparameters will compare (==) as equal.All instances that compare equal will hash to the same value.