OpenQuizz
Une application de gestion des contenus pédagogiques
attr.converters Namespace Reference

Functions

def optional (converter)
 
def default_if_none (default=NOTHING, factory=None)
 

Detailed Description

Commonly useful converters.

Function Documentation

◆ default_if_none()

def attr.converters.default_if_none (   default = NOTHING,
  factory = None 
)
A converter that allows to replace ``None`` values by *default* or the
result of *factory*.

:param default: Value to be used if ``None`` is passed. Passing an instance
   of `attr.Factory` is supported, however the ``takes_self`` option
   is *not*.
:param callable factory: A callable that takes no parameters whose result
   is used if ``None`` is passed.

:raises TypeError: If **neither** *default* or *factory* is passed.
:raises TypeError: If **both** *default* and *factory* are passed.
:raises ValueError: If an instance of `attr.Factory` is passed with
   ``takes_self=True``.

.. versionadded:: 18.2.0

◆ optional()

def attr.converters.optional (   converter)
A converter that allows an attribute to be optional. An optional attribute
is one which can be set to ``None``.

Type annotations will be inferred from the wrapped converter's, if it
has any.

:param callable converter: the converter that is used for non-``None``
    values.

.. versionadded:: 17.1.0