@@ -335,20 +335,23 @@ def _check_raise_missing_from(self, node: nodes.Raise) -> None:
335335 # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
336336 # SomeException`.
337337
338- need_to_raise = False
339- except_as_exc = ""
340- exception_name = "exc"
341338 if containing_except_node .name is None :
342339 # The `except` doesn't have an `as exception:` part, meaning there's no way that
343340 # the `raise` is raising the same exception.
341+ class_of_old_error = "Exception"
344342 if isinstance (containing_except_node .type , nodes .Name ):
345343 class_of_old_error = containing_except_node .type .name
346344 elif isinstance (containing_except_node .type , nodes .Tuple ):
347345 class_of_old_error = ", " .join (
348346 n .name for n in containing_except_node .type .elts
349347 )
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+ )
352355 elif (
353356 isinstance (node .exc , nodes .Call )
354357 and isinstance (node .exc .func , nodes .Name )
@@ -358,13 +361,10 @@ def _check_raise_missing_from(self, node: nodes.Raise) -> None:
358361 )
359362 ):
360363 # 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 :
364364 self .add_message (
365365 "raise-missing-from" ,
366366 node = node ,
367- args = (except_as_exc , node .as_string (), exception_name ),
367+ args = ("" , node .as_string (), containing_except_node . name . name ),
368368 confidence = HIGH ,
369369 )
370370
0 commit comments