more descriptive exceptions

This commit is contained in:
abdullaev388 2022-02-16 12:29:27 +05:00
parent 8c3d1e608c
commit b41435f407
2 changed files with 10 additions and 10 deletions

View File

@ -61,16 +61,16 @@ class TextFilter:
raise ValueError('None of the check modes was specified')
self.equals = equals
self.contains = self._check_iterable(contains)
self.starts_with = self._check_iterable(starts_with)
self.ends_with = self._check_iterable(ends_with)
self.contains = self._check_iterable(contains, filter_name='contains')
self.starts_with = self._check_iterable(starts_with, filter_name='starts_with')
self.ends_with = self._check_iterable(ends_with, filter_name='ends_with')
self.ignore_case = ignore_case
def _check_iterable(self, iterable):
def _check_iterable(self, iterable, filter_name):
if not iterable:
pass
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
raise ValueError
raise ValueError(f"Incorrect value of {filter_name!r}")
elif isinstance(iterable, str):
iterable = [iterable]
elif isinstance(iterable, list) or isinstance(iterable, tuple):

View File

@ -61,16 +61,16 @@ class TextFilter:
raise ValueError('None of the check modes was specified')
self.equals = equals
self.contains = self._check_iterable(contains)
self.starts_with = self._check_iterable(starts_with)
self.ends_with = self._check_iterable(ends_with)
self.contains = self._check_iterable(contains, filter_name='contains')
self.starts_with = self._check_iterable(starts_with, filter_name='starts_with')
self.ends_with = self._check_iterable(ends_with, filter_name='ends_with')
self.ignore_case = ignore_case
def _check_iterable(self, iterable):
def _check_iterable(self, iterable, filter_name: str):
if not iterable:
pass
elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple):
raise ValueError
raise ValueError(f"Incorrect value of {filter_name!r}")
elif isinstance(iterable, str):
iterable = [iterable]
elif isinstance(iterable, list) or isinstance(iterable, tuple):