Skip to content

Commit 7bf1176

Browse files
cool-RRPierre-Sassoulas
authored andcommitted
Fix exception causes all over the codebase
1 parent 201daa6 commit 7bf1176

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

pylint/checkers/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ def report_by_type_stats(sect, stats, _):
396396
for node_type in ("module", "class", "method", "function"):
397397
try:
398398
total = stats[node_type]
399-
except KeyError:
400-
raise exceptions.EmptyReportError()
399+
except KeyError as e:
400+
raise exceptions.EmptyReportError() from e
401401
nice_stats[node_type] = {}
402402
if total != 0:
403403
try:

pylint/checkers/typecheck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ def _determine_callable(callable_obj):
536536
try:
537537
# Use the last definition of __init__.
538538
callable_obj = callable_obj.local_attr("__init__")[-1]
539-
except exceptions.NotFoundError:
539+
except exceptions.NotFoundError as e:
540540
# do nothing, covered by no-init.
541-
raise ValueError
541+
raise ValueError from e
542542
else:
543543
callable_obj = new
544544

pylint/checkers/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ def next_char(i):
533533
def split_format_field_names(format_string) -> Tuple[str, Iterable[Tuple[bool, str]]]:
534534
try:
535535
return _string.formatter_field_name_split(format_string)
536-
except ValueError:
537-
raise IncompleteFormatString()
536+
except ValueError as e:
537+
raise IncompleteFormatString() from e
538538

539539

540540
def collect_string_fields(format_string) -> Iterable[Optional[str]]:
@@ -566,7 +566,7 @@ def collect_string_fields(format_string) -> Iterable[Optional[str]]:
566566
yield ""
567567
yield "1"
568568
return
569-
raise IncompleteFormatString(format_string)
569+
raise IncompleteFormatString(format_string) from exc
570570

571571

572572
def parse_format_method_string(
@@ -591,8 +591,8 @@ def parse_format_method_string(
591591
explicit_pos_args.add(str(keyname))
592592
try:
593593
keyword_arguments.append((keyname, list(fielditerator)))
594-
except ValueError:
595-
raise IncompleteFormatString()
594+
except ValueError as e:
595+
raise IncompleteFormatString() from e
596596
else:
597597
implicit_pos_args_cnt += 1
598598
return keyword_arguments, implicit_pos_args_cnt, len(explicit_pos_args)

pylint/config/option.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def _call_validator(opttype, optdict, option, value):
8686
except TypeError:
8787
try:
8888
return VALIDATORS[opttype](value)
89-
except Exception:
89+
except Exception as e:
9090
raise optparse.OptionValueError(
9191
"%s value (%r) should be of type %s" % (option, value, opttype)
92-
)
92+
) from e
9393

9494

9595
def _validate(value, optdict, name=""):

pylint/lint/pylinter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ def _load_reporter(self):
509509
else:
510510
try:
511511
reporter_class = self._load_reporter_class()
512-
except (ImportError, AttributeError):
513-
raise exceptions.InvalidReporterError(name)
512+
except (ImportError, AttributeError) as e:
513+
raise exceptions.InvalidReporterError(name) from e
514514
else:
515515
self.set_reporter(reporter_class())
516516

pylint/pyreverse/vcgutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ def _write_attributes(self, attributes_dict, **args):
198198
for key, value in args.items():
199199
try:
200200
_type = attributes_dict[key]
201-
except KeyError:
201+
except KeyError as e:
202202
raise Exception(
203203
"""no such attribute %s
204204
possible attributes are %s"""
205205
% (key, attributes_dict.keys())
206-
)
206+
) from e
207207

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

0 commit comments

Comments
 (0)