'Used as a decorator to set the validator method for a `Parameter`.
The validator method validates any value set for that parameter.
It takes two arguments--``self``, which refers to the `Model`
instance (remember, this is a method defined on a `Model`), and
the value being set for this parameter.  The validator method\'s
return value is ignored, but it may raise an exception if the value
set on the parameter is invalid (typically an `InputParameterError`
should be raised, though this is not currently a requirement).
The decorator *returns* the `Parameter` instance that the validator
is set on, so the underlying validator method should have the same
name as the `Parameter` itself (think of this as analogous to
``property.setter``).  For example::
>>> from astropy.modeling import Fittable1DModel
>>> class TestModel(Fittable1DModel):
...     a = Parameter()
...     b = Parameter()
...     @a.validator
...     def a(self, value):
...         # Remember, the value can be an array
...         if np.any(value < self.b):
...             raise InputParameterError(
...                 "parameter \'a\' must be greater than or equal "
...                 "to parameter \'b\'")
...     @staticmethod
...     def evaluate(x, a, b):
...         return a * x + b
>>> m = TestModel(a=1, b=2)  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
InputParameterError: parameter \'a\' must be greater than or equal
to parameter \'b\'
>>> m = TestModel(a=2, b=2)
>>> m.a = 0  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
InputParameterError: parameter \'a\' must be greater than or equal
to parameter \'b\'
On bound parameters this property returns the validator method itself,
as a bound method on the `Parameter`.  This is not often as useful, but
it allows validating a parameter value without setting that parameter::
>>> m.a.validator(42)  # Passes
>>> m.a.validator(-42)  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
InputParameterError: parameter \'a\' must be greater than or equal
to parameter \'b\''

@property
def validator(self):

    if (self._model is None):
        def validator(func, self=self):
            self._validator = func
            return self
        return validator
    else:
        def validator(self, value):
            if (self._validator is not None):
                return self._validator(self._model, value)
        if six.PY2:
            return types.MethodType(validator, self, type(self))
        else:
            return types.MethodType(validator, self)
