from typing import Callable
import pydantic


def _validator(*names, fn: Callable) -> Callable:
    """Construct reusable Pydantic validator.

    Args:
        names: Names of attributes to validate.
        fn: Validation function (see :meth:`pydantic.validator`).

    Examples:
        >>> class Class(Base):
        ...     x: list = None
        ...     _check_unique = _validator("x", fn=_check_unique)
        >>> Class(y=[0, 0])
        Traceback (most recent call last):
        ValidationError: ...
    """
    return pydantic.validator(*names, allow_reuse=True)(fn)