def error(self, instance, value, error_class=None, extra=''):
"""Generate a :code:`ValueError` for invalid value assignment
The instance is the containing HasProperties instance, but it may
be None if the error is raised outside a HasProperties class.
"""
error_class = error_class if error_class is not None else ValueError
prefix = 'The {} property'.format(self.__class__.__name__)
if self.name != '':
prefix = prefix + " '{}'".format(self.name)
if instance is not None:
prefix = prefix + ' of a {cls} instance'.format(
cls=instance.__class__.__name__,
)
raise error_class(
'{prefix} must be {info}. A value of {val!r} {vtype!r} was '
'specified. {extra}'.format(
prefix=prefix,
info=self.info or 'corrected',
val=value,
vtype=type(value),
extra=extra,
)
)
评论列表
文章目录