add index in warnings

This commit is contained in:
Emmanuel Garette 2019-02-13 22:49:27 +01:00
parent 526fe892d0
commit 0a3b0e913f
2 changed files with 17 additions and 10 deletions

View file

@ -159,11 +159,13 @@ class _CommonError:
val,
display_type,
opt,
err_msg):
err_msg,
index):
self.val = val
self.display_type = display_type
self.opt = weakref.ref(opt)
self.err_msg = err_msg
self.index = index
super().__init__(self.err_msg)
def __str__(self):

View file

@ -302,13 +302,15 @@ class Option(BaseOption):
warnings.warn_explicit(ValueWarning(_value,
self._display_name,
self,
err_msg = '{0}'.format(err)),
'{0}'.format(err),
_index),
ValueWarning,
self.__class__.__name__, 0)
else:
raise err
try:
val = value
err_index = force_index
if not self.impl_is_multi():
do_validation(val, None)
elif force_index is not None:
@ -316,7 +318,7 @@ class Option(BaseOption):
if not isinstance(value, list):
raise ValueError(_('which must be a list'))
_is_not_unique(value)
for idx, val in enumerate(value):
for val in value:
do_validation(val,
force_index)
else:
@ -325,19 +327,19 @@ class Option(BaseOption):
elif not isinstance(value, list):
raise ValueError(_('which must be a list'))
elif self.impl_is_submulti():
for idx, lval in enumerate(value):
for err_index, lval in enumerate(value):
_is_not_unique(lval)
if not isinstance(lval, list):
raise ValueError(_('which "{}" must be a list of list'
'').format(lval))
for val in lval:
do_validation(val,
idx)
err_index)
else:
_is_not_unique(value)
for idx, val in enumerate(value):
for err_index, val in enumerate(value):
do_validation(val,
idx)
err_index)
if not is_warnings_only or not check_error:
self.valid_consistency(option_bag,
@ -350,11 +352,13 @@ class Option(BaseOption):
raise ValueOptionError(val,
self._display_name,
option_bag.ori_option,
'{0}'.format(err))
'{0}'.format(err),
err_index)
warnings.warn_explicit(ValueErrorWarning(val,
self._display_name,
option_bag.ori_option,
'{0}'.format(err)),
'{0}'.format(err),
err_index),
ValueErrorWarning,
self.__class__.__name__, 0)
@ -635,7 +639,8 @@ class Option(BaseOption):
warnings.warn_explicit(ValueWarning(value,
self._display_name,
current_opt,
"{}".format(err)),
"{}".format(err),
option_bag.index),
ValueWarning,
self.__class__.__name__, 0)
else: