@@ -335,20 +335,23 @@ def _check_raise_missing_from(self, node: nodes.Raise) -> None:
335
335
# there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
336
336
# SomeException`.
337
337
338
- need_to_raise = False
339
- except_as_exc = ""
340
- exception_name = "exc"
341
338
if containing_except_node .name is None :
342
339
# The `except` doesn't have an `as exception:` part, meaning there's no way that
343
340
# the `raise` is raising the same exception.
341
+ class_of_old_error = "Exception"
344
342
if isinstance (containing_except_node .type , nodes .Name ):
345
343
class_of_old_error = containing_except_node .type .name
346
344
elif isinstance (containing_except_node .type , nodes .Tuple ):
347
345
class_of_old_error = ", " .join (
348
346
n .name for n in containing_except_node .type .elts
349
347
)
350
- except_as_exc = f"'except { class_of_old_error } as { exception_name } ' and "
351
- need_to_raise = True
348
+ except_as_exc = f"'except { class_of_old_error } as exc' and "
349
+ self .add_message (
350
+ "raise-missing-from" ,
351
+ node = node ,
352
+ args = (except_as_exc , node .as_string (), "exc" ),
353
+ confidence = HIGH ,
354
+ )
352
355
elif (
353
356
isinstance (node .exc , nodes .Call )
354
357
and isinstance (node .exc .func , nodes .Name )
@@ -358,13 +361,10 @@ def _check_raise_missing_from(self, node: nodes.Raise) -> None:
358
361
)
359
362
):
360
363
# We have a `raise SomeException(whatever)` or a `raise SomeException`
361
- exception_name = containing_except_node .name .name
362
- need_to_raise = True
363
- if need_to_raise :
364
364
self .add_message (
365
365
"raise-missing-from" ,
366
366
node = node ,
367
- args = (except_as_exc , node .as_string (), exception_name ),
367
+ args = ("" , node .as_string (), containing_except_node . name . name ),
368
368
confidence = HIGH ,
369
369
)
370
370
0 commit comments