Skip to content

Fix exception causes all over the codebase #3681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def report_by_type_stats(sect, stats, _):
for node_type in ("module", "class", "method", "function"):
try:
total = stats[node_type]
except KeyError:
raise exceptions.EmptyReportError()
except KeyError as e:
raise exceptions.EmptyReportError() from e
nice_stats[node_type] = {}
if total != 0:
try:
Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ def _determine_callable(callable_obj):
try:
# Use the last definition of __init__.
callable_obj = callable_obj.local_attr("__init__")[-1]
except exceptions.NotFoundError:
except exceptions.NotFoundError as e:
# do nothing, covered by no-init.
raise ValueError
raise ValueError from e
else:
callable_obj = new

Expand Down
10 changes: 5 additions & 5 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ def next_char(i):
def split_format_field_names(format_string) -> Tuple[str, Iterable[Tuple[bool, str]]]:
try:
return _string.formatter_field_name_split(format_string)
except ValueError:
raise IncompleteFormatString()
except ValueError as e:
raise IncompleteFormatString() from e


def collect_string_fields(format_string) -> Iterable[Optional[str]]:
Expand Down Expand Up @@ -566,7 +566,7 @@ def collect_string_fields(format_string) -> Iterable[Optional[str]]:
yield ""
yield "1"
return
raise IncompleteFormatString(format_string)
raise IncompleteFormatString(format_string) from exc


def parse_format_method_string(
Expand All @@ -591,8 +591,8 @@ def parse_format_method_string(
explicit_pos_args.add(str(keyname))
try:
keyword_arguments.append((keyname, list(fielditerator)))
except ValueError:
raise IncompleteFormatString()
except ValueError as e:
raise IncompleteFormatString() from e
else:
implicit_pos_args_cnt += 1
return keyword_arguments, implicit_pos_args_cnt, len(explicit_pos_args)
Expand Down
4 changes: 2 additions & 2 deletions pylint/config/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def _call_validator(opttype, optdict, option, value):
except TypeError:
try:
return VALIDATORS[opttype](value)
except Exception:
except Exception as e:
raise optparse.OptionValueError(
"%s value (%r) should be of type %s" % (option, value, opttype)
)
) from e


def _validate(value, optdict, name=""):
Expand Down
4 changes: 2 additions & 2 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ def _load_reporter(self):
else:
try:
reporter_class = self._load_reporter_class()
except (ImportError, AttributeError):
raise exceptions.InvalidReporterError(name)
except (ImportError, AttributeError) as e:
raise exceptions.InvalidReporterError(name) from e
else:
self.set_reporter(reporter_class())

Expand Down
4 changes: 2 additions & 2 deletions pylint/pyreverse/vcgutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ def _write_attributes(self, attributes_dict, **args):
for key, value in args.items():
try:
_type = attributes_dict[key]
except KeyError:
except KeyError as e:
raise Exception(
"""no such attribute %s
possible attributes are %s"""
% (key, attributes_dict.keys())
)
) from e

if not _type:
self._stream.write('%s%s:"%s"\n' % (self._indent, key, value))
Expand Down