Set a name on a validator callable.

    Useful for user-friendly reporting when using lambdas to populate the [`Invalid.expected`](#invalid) field:

    ```python
    from good import Schema, name

    Schema(lambda x: int(x))('a')
    #-> Invalid: invalid literal for int(): expected <lambda>(), got
    Schema(name('int()', lambda x: int(x))('a')
    #-> Invalid: invalid literal for int(): expected int(), got a
    ```

    Note that it is only useful with lambdas, since function name is used if available:
    see notes on [Schema Callables](#callables).

    :param name: Name to assign on the validator callable
    :type name: unicode
    :param validator: Validator callable. If not provided -- a decorator is returned instead:

        ```python
        from good import name

        @name(u'int()')
        def int(v):
            return int(v)
        ```

    :type validator: callable
    :return: The same validator callable
    :rtype: callable

def name(name, validator=None):
    """ Set a name on a validator callable.

    Useful for user-friendly reporting when using lambdas to populate the [`Invalid.expected`](#invalid) field:

    ```python
    from good import Schema, name

    Schema(lambda x: int(x))('a')
    #-> Invalid: invalid literal for int(): expected <lambda>(), got
    Schema(name('int()', lambda x: int(x))('a')
    #-> Invalid: invalid literal for int(): expected int(), got a
    ```

    Note that it is only useful with lambdas, since function name is used if available:
    see notes on [Schema Callables](#callables).

    :param name: Name to assign on the validator callable
    :type name: unicode
    :param validator: Validator callable. If not provided -- a decorator is returned instead:

        ```python
        from good import name

        @name(u'int()')
        def int(v):
            return int(v)
        ```

    :type validator: callable
    :return: The same validator callable
    :rtype: callable
    """
    # Decorator mode
    if validator is None:
        def decorator(f):
            f.name = name
            return f
        return decorator

    # Direct mode
    validator.name = name
    return validator