OpenQuizz
Une application de gestion des contenus pédagogiques
PClass Class Reference
Inheritance diagram for PClass:
Collaboration diagram for PClass:

Public Member Functions

def __new__ (cls, **kwargs)
 
def set (self, *args, **kwargs)
 
def create (cls, kwargs, _factory_fields=None, ignore_extra=False)
 
def serialize (self, format=None)
 
def transform (self, *transformations)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def __setattr__ (self, key, value)
 
def __delattr__ (self, key)
 
def __repr__ (self)
 
def __reduce__ (self)
 
def evolver (self)
 
def remove (self, name)
 
- Public Member Functions inherited from CheckedType
def create (cls, source_data, _factory_fields=None)
 
- Public Member Functions inherited from PClassMeta
def __new__ (mcs, name, bases, dct)
 

Detailed Description

A PClass is a python class with a fixed set of specified fields. PClasses are declared as python classes inheriting
from PClass. It is defined the same way that PRecords are and behaves like a PRecord in all aspects except that it
is not a PMap and hence not a collection but rather a plain Python object.


More documentation and examples of PClass usage is available at https://github.com/tobgu/pyrsistent

Member Function Documentation

◆ __delattr__()

def __delattr__ (   self,
  key 
)

◆ __eq__()

def __eq__ (   self,
  other 
)

◆ __hash__()

def __hash__ (   self)

◆ __ne__()

def __ne__ (   self,
  other 
)

◆ __new__()

def __new__ (   cls,
**  kwargs 
)

◆ __reduce__()

def __reduce__ (   self)

◆ __repr__()

def __repr__ (   self)

◆ __setattr__()

def __setattr__ (   self,
  key,
  value 
)

◆ create()

def create (   cls,
  kwargs,
  _factory_fields = None,
  ignore_extra = False 
)
Factory method. Will create a new PClass of the current type and assign the values
specified in kwargs.

:param ignore_extra: A boolean which when set to True will ignore any keys which appear in kwargs that are not
             in the set of fields on the PClass.

◆ evolver()

def evolver (   self)
Returns an evolver for this object.

◆ remove()

def remove (   self,
  name 
)
Remove attribute given by name from the current instance. Raises AttributeError if the
attribute doesn't exist.

◆ serialize()

def serialize (   self,
  format = None 
)
Serialize the current PClass using custom serializer functions for fields where
such have been supplied.

Reimplemented from CheckedType.

◆ set()

def set (   self,
args,
**  kwargs 
)
Set a field in the instance. Returns a new instance with the updated value. The original instance remains
unmodified. Accepts key-value pairs or single string representing the field name and a value.

>>> from pyrsistent import PClass, field
>>> class AClass(PClass):
...     x = field()
...
>>> a = AClass(x=1)
>>> a2 = a.set(x=2)
>>> a3 = a.set('x', 3)
>>> a
AClass(x=1)
>>> a2
AClass(x=2)
>>> a3
AClass(x=3)

◆ transform()

def transform (   self,
transformations 
)
Apply transformations to the currency PClass. For more details on transformations see
the documentation for PMap. Transformations on PClasses do not support key matching
since the PClass is not a collection. Apart from that the transformations available
for other persistent types work as expected.

The documentation for this class was generated from the following file: