The FrozenState Class

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.

    1. cls - the class of the State being frozen. This should be an instance of the class or type type.

    2. state - an object representing the internal state of the State instance being frozen.

    3. thawer - optional. If specified, this should be a function that will be used to thaw (aka, "unfreeze") the FrozenState instance. When invoked, this function will be passed two parameters: first, the type of the State being thawed (the cls parameter); second, the internal state of the to-be-unfrozen State (the state parameter).

      If this is left unspecified or is None, it assumed that the cls class defines defines a _thaw classmethod.

  • FrozenState defines a freeze method. This merely returns the invocant.

  • FrozenState defines a thaw method. This is used to thaw -- or "unfreeze" -- the State instance represented in the invocant. thaw returns an instance of the State class. The returned State instance will be a deep copy of the instance that was originally frozen.

  • FrozenState instances that were created with the same cls and state parameters will compare (==) as equal.

    All instances that compare equal will hash to the same value.

svnmock