Skip to content

Commit 72c5e55

Browse files
[raise-missing-from] Clearer message and example in the documentation
Co-authored-by: cool-RR <[email protected]> Refs #5953 Closes #3707
1 parent 3721bef commit 72c5e55

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
1 / 0
3+
except ZeroDivisionError as e:
4+
raise ValueError("Rectangle Area cannot be zero") # [raise-missing-from]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
You are raising the %s exception after the %s exception was caught.
2+
It's likely that the second exception is a friendly re-wrapping of the first exception,
3+
therefore you should use ``raise new_exception from old_exception`` to see an accurate message
4+
between the two tracebacks.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
1 / 0
3+
except ZeroDivisionError as e:
4+
raise ValueError("Rectangle Area cannot be zero") from e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- `PEP 3132 <https://www.python.org/dev/peps/pep-3132/>`_

pylint/checkers/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _is_raising(body: list) -> bool:
131131
"try-except-raise block!",
132132
),
133133
"W0707": (
134-
"Consider explicitly re-raising using the 'from' keyword",
134+
"Consider explicitly re-raising using 'raise NewError(...) from old_error'",
135135
"raise-missing-from",
136136
"Python 3's exception chaining means it shows the traceback of the "
137137
"current exception, but also the original exception. Not using `raise "
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
raise-missing-from:11:4:11:18::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
2-
raise-missing-from:19:4:19:25::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
3-
raise-missing-from:25:4:25:18::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
4-
raise-missing-from:31:4:31:18::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
5-
raise-missing-from:45:20:45:34::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
6-
raise-missing-from:53:4:53:20::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
7-
raise-missing-from:59:4:59:47::Consider explicitly re-raising using the 'from' keyword:UNDEFINED
1+
raise-missing-from:11:4:11:18::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
2+
raise-missing-from:19:4:19:25::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
3+
raise-missing-from:25:4:25:18::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
4+
raise-missing-from:31:4:31:18::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
5+
raise-missing-from:45:20:45:34::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
6+
raise-missing-from:53:4:53:20::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED
7+
raise-missing-from:59:4:59:47::Consider explicitly re-raising using 'raise NewError(...) from old_error':UNDEFINED

0 commit comments

Comments
 (0)