Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions
attr.validators Namespace Reference

Classes

class  _DeepIterable
 
class  _DeepMapping
 
class  _InstanceOfValidator
 
class  _InValidator
 
class  _IsCallableValidator
 
class  _MatchesReValidator
 
class  _MaxLengthValidator
 
class  _MinLengthValidator
 
class  _NotValidator
 
class  _NumberValidator
 
class  _OptionalValidator
 
class  _OrValidator
 
class  _SubclassOfValidator
 

Functions

 set_disabled (disabled)
 
 get_disabled ()
 
 disabled ()
 
 instance_of (type)
 
 matches_re (regex, flags=0, func=None)
 
 optional (validator)
 
 in_ (options)
 
 is_callable ()
 
 deep_iterable (member_validator, iterable_validator=None)
 
 deep_mapping (key_validator=None, value_validator=None, mapping_validator=None)
 
 lt (val)
 
 le (val)
 
 ge (val)
 
 gt (val)
 
 max_len (length)
 
 min_len (length)
 
 _subclass_of (type)
 
 not_ (validator, *msg=None, exc_types=(ValueError, TypeError))
 
 or_ (*validators)
 

Detailed Description

Commonly useful validators.

Function Documentation

◆ _subclass_of()

attr.validators._subclass_of (   type)
protected
A validator that raises a `TypeError` if the initializer is called with a
wrong type for this particular attribute (checks are performed using
`issubclass` therefore it's also valid to pass a tuple of types).

Args:
    type (type | tuple[type, ...]): The type(s) to check for.

Raises:
    TypeError:
        With a human readable error message, the attribute (of type
        `attrs.Attribute`), the expected type, and the value it got.

◆ deep_iterable()

attr.validators.deep_iterable (   member_validator,
  iterable_validator = None 
)
A validator that performs deep validation of an iterable.

Args:
    member_validator: Validator(s) to apply to iterable members.

    iterable_validator:
        Validator(s) to apply to iterable itself (optional).

Raises
    TypeError: if any sub-validators fail

.. versionadded:: 19.1.0

.. versionchanged:: 25.4.0
   *member_validator* and *iterable_validator* can now be a list or tuple
   of validators.

◆ deep_mapping()

attr.validators.deep_mapping (   key_validator = None,
  value_validator = None,
  mapping_validator = None 
)
A validator that performs deep validation of a dictionary.

All validators are optional, but at least one of *key_validator* or
*value_validator* must be provided.

Args:
    key_validator: Validator(s) to apply to dictionary keys.

    value_validator: Validator(s) to apply to dictionary values.

    mapping_validator:
        Validator(s) to apply to top-level mapping attribute.

.. versionadded:: 19.1.0

.. versionchanged:: 25.4.0
   *key_validator* and *value_validator* are now optional, but at least one
   of them must be provided.

.. versionchanged:: 25.4.0
   *key_validator*, *value_validator*, and *mapping_validator* can now be a
   list or tuple of validators.

Raises:
    TypeError: If any sub-validator fails on validation.

    ValueError:
        If neither *key_validator* nor *value_validator* is provided on
        instantiation.

◆ disabled()

attr.validators.disabled ( )
Context manager that disables running validators within its context.

.. warning::

    This context manager is not thread-safe!

.. versionadded:: 21.3.0

◆ ge()

attr.validators.ge (   val)
A validator that raises `ValueError` if the initializer is called with a
number smaller than *val*.

The validator uses `operator.ge` to compare the values.

Args:
    val: Inclusive lower bound for values

.. versionadded:: 21.3.0

◆ get_disabled()

attr.validators.get_disabled ( )
Return a bool indicating whether validators are currently disabled or not.

Returns:
    bool:`True` if validators are currently disabled.

.. versionadded:: 21.3.0

◆ gt()

attr.validators.gt (   val)
A validator that raises `ValueError` if the initializer is called with a
number smaller or equal to *val*.

The validator uses `operator.gt` to compare the values.

Args:
   val: Exclusive lower bound for values

.. versionadded:: 21.3.0

◆ in_()

attr.validators.in_ (   options)
A validator that raises a `ValueError` if the initializer is called with a
value that does not belong in the *options* provided.

The check is performed using ``value in options``, so *options* has to
support that operation.

To keep the validator hashable, dicts, lists, and sets are transparently
transformed into a `tuple`.

Args:
    options: Allowed options.

Raises:
    ValueError:
        With a human readable error message, the attribute (of type
        `attrs.Attribute`), the expected options, and the value it got.

.. versionadded:: 17.1.0
.. versionchanged:: 22.1.0
   The ValueError was incomplete until now and only contained the human
   readable error message. Now it contains all the information that has
   been promised since 17.1.0.
.. versionchanged:: 24.1.0
   *options* that are a list, dict, or a set are now transformed into a
   tuple to keep the validator hashable.

◆ instance_of()

attr.validators.instance_of (   type)
A validator that raises a `TypeError` if the initializer is called with a
wrong type for this particular attribute (checks are performed using
`isinstance` therefore it's also valid to pass a tuple of types).

Args:
    type (type | tuple[type]): The type to check for.

Raises:
    TypeError:
        With a human readable error message, the attribute (of type
        `attrs.Attribute`), the expected type, and the value it got.

◆ is_callable()

attr.validators.is_callable ( )
A validator that raises a `attrs.exceptions.NotCallableError` if the
initializer is called with a value for this particular attribute that is
not callable.

.. versionadded:: 19.1.0

Raises:
    attrs.exceptions.NotCallableError:
        With a human readable error message containing the attribute
        (`attrs.Attribute`) name, and the value it got.

◆ le()

attr.validators.le (   val)
A validator that raises `ValueError` if the initializer is called with a
number greater than *val*.

The validator uses `operator.le` to compare the values.

Args:
    val: Inclusive upper bound for values.

.. versionadded:: 21.3.0

◆ lt()

attr.validators.lt (   val)
A validator that raises `ValueError` if the initializer is called with a
number larger or equal to *val*.

The validator uses `operator.lt` to compare the values.

Args:
    val: Exclusive upper bound for values.

.. versionadded:: 21.3.0

◆ matches_re()

attr.validators.matches_re (   regex,
  flags = 0,
  func = None 
)
A validator that raises `ValueError` if the initializer is called with a
string that doesn't match *regex*.

Args:
regex (str, re.Pattern):
    A regex string or precompiled pattern to match against

flags (int):
    Flags that will be passed to the underlying re function (default 0)

func (typing.Callable):
    Which underlying `re` function to call. Valid options are
    `re.fullmatch`, `re.search`, and `re.match`; the default `None`
    means `re.fullmatch`. For performance reasons, the pattern is
    always precompiled using `re.compile`.

.. versionadded:: 19.2.0
.. versionchanged:: 21.3.0 *regex* can be a pre-compiled pattern.

◆ max_len()

attr.validators.max_len (   length)
A validator that raises `ValueError` if the initializer is called
with a string or iterable that is longer than *length*.

Args:
    length (int): Maximum length of the string or iterable

.. versionadded:: 21.3.0

◆ min_len()

attr.validators.min_len (   length)
A validator that raises `ValueError` if the initializer is called
with a string or iterable that is shorter than *length*.

Args:
    length (int): Minimum length of the string or iterable

.. versionadded:: 22.1.0

◆ not_()

attr.validators.not_ (   validator,
msg = None,
  exc_types = (ValueError, TypeError) 
)
A validator that wraps and logically 'inverts' the validator passed to it.
It will raise a `ValueError` if the provided validator *doesn't* raise a
`ValueError` or `TypeError` (by default), and will suppress the exception
if the provided validator *does*.

Intended to be used with existing validators to compose logic without
needing to create inverted variants, for example, ``not_(in_(...))``.

Args:
    validator: A validator to be logically inverted.

    msg (str):
        Message to raise if validator fails. Formatted with keys
        ``exc_types`` and ``validator``.

    exc_types (tuple[type, ...]):
        Exception type(s) to capture. Other types raised by child
        validators will not be intercepted and pass through.

Raises:
    ValueError:
        With a human readable error message, the attribute (of type
        `attrs.Attribute`), the validator that failed to raise an
        exception, the value it got, and the expected exception types.

.. versionadded:: 22.2.0

◆ optional()

attr.validators.optional (   validator)
A validator that makes an attribute optional.  An optional attribute is one
which can be set to `None` in addition to satisfying the requirements of
the sub-validator.

Args:
    validator
        (typing.Callable | tuple[typing.Callable] | list[typing.Callable]):
        A validator (or validators) that is used for non-`None` values.

.. versionadded:: 15.1.0
.. versionchanged:: 17.1.0 *validator* can be a list of validators.
.. versionchanged:: 23.1.0 *validator* can also be a tuple of validators.

◆ or_()

attr.validators.or_ ( validators)
A validator that composes multiple validators into one.

When called on a value, it runs all wrapped validators until one of them is
satisfied.

Args:
    validators (~collections.abc.Iterable[typing.Callable]):
        Arbitrary number of validators.

Raises:
    ValueError:
        If no validator is satisfied. Raised with a human-readable error
        message listing all the wrapped validators and the value that
        failed all of them.

.. versionadded:: 24.1.0

◆ set_disabled()

attr.validators.set_disabled (   disabled)
Globally disable or enable running validators.

By default, they are run.

Args:
    disabled (bool): If `True`, disable running all validators.

.. warning::

    This function is not thread-safe!

.. versionadded:: 21.3.0