OpenQuizz
Une application de gestion des contenus pédagogiques
pyrsistent._helpers Namespace Reference

Functions

def freeze (o)
 
def thaw (o)
 
def mutant (fn)
 

Function Documentation

◆ freeze()

def pyrsistent._helpers.freeze (   o)
Recursively convert simple Python containers into pyrsistent versions
of those containers.

- list is converted to pvector, recursively
- dict is converted to pmap, recursively on values (but not keys)
- set is converted to pset, but not recursively
- tuple is converted to tuple, recursively.

Sets and dict keys are not recursively frozen because they do not contain
mutable data by convention. The main exception to this rule is that
dict keys and set elements are often instances of mutable objects that
support hash-by-id, which this function can't convert anyway.

>>> freeze(set([1, 2]))
pset([1, 2])
>>> freeze([1, {'a': 3}])
pvector([1, pmap({'a': 3})])
>>> freeze((1, []))
(1, pvector([]))

◆ mutant()

def pyrsistent._helpers.mutant (   fn)
Convenience decorator to isolate mutation to within the decorated function (with respect
to the input arguments).

All arguments to the decorated function will be frozen so that they are guaranteed not to change.
The return value is also frozen.

◆ thaw()

def pyrsistent._helpers.thaw (   o)
Recursively convert pyrsistent containers into simple Python containers.

- pvector is converted to list, recursively
- pmap is converted to dict, recursively on values (but not keys)
- pset is converted to set, but not recursively
- tuple is converted to tuple, recursively.

>>> from pyrsistent import s, m, v
>>> thaw(s(1, 2))
{1, 2}
>>> thaw(v(1, m(a=3)))
[1, {'a': 3}]
>>> thaw((1, v()))
(1, [])