OpenQuizz
Une application de gestion des contenus pédagogiques
|
Functions | |
def | optional (converter) |
def | default_if_none (default=NOTHING, factory=None) |
Commonly useful converters.
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
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