Path 1: 244 calls (0.9)

Raise (244)

None (244)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 2: 13 calls (0.05)

Raise (13)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 3: 5 calls (0.02)

Raise (5)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 4: 3 calls (0.01)

Raise (3)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 5: 3 calls (0.01)

Raise (3)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 6: 2 calls (0.01)

Raise (2)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 7: 1 calls (0.0)

Raise (1)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )
            

Path 8: 1 calls (0.0)

Raise (1)

1def _check_raise_missing_from(self, node: nodes.Raise) -> None:
2        if node.exc is None:
3            # This is a plain `raise`, raising the previously-caught exception. No need for a
4            # cause.
5            return
6        # We'd like to check whether we're inside an `except` clause:
7        containing_except_node = utils.find_except_wrapper_node_in_scope(node)
8        if not containing_except_node:
9            return
10        # We found a surrounding `except`! We're almost done proving there's a
11        # `raise-missing-from` here. The only thing we need to protect against is that maybe
12        # the `raise` is raising the exception that was caught, possibly with some shenanigans
13        # like `exc.with_traceback(whatever)`. We won't analyze these, we'll just assume
14        # there's a violation on two simple cases: `raise SomeException(whatever)` and `raise
15        # SomeException`.
16        if containing_except_node.name is None:
17            # The `except` doesn't have an `as exception:` part, meaning there's no way that
18            # the `raise` is raising the same exception.
19            class_of_old_error = "Exception"
20            if isinstance(containing_except_node.type, (nodes.Name, nodes.Tuple)):
21                # 'except ZeroDivisionError' or 'except (ZeroDivisionError, ValueError)'
22                class_of_old_error = containing_except_node.type.as_string()
23            self.add_message(
24                "raise-missing-from",
25                node=node,
26                args=(
27                    f"'except {class_of_old_error} as exc' and ",
28                    node.as_string(),
29                    "exc",
30                ),
31                confidence=HIGH,
32            )
33        elif (
34            isinstance(node.exc, nodes.Call)
35            and isinstance(node.exc.func, nodes.Name)
36            or isinstance(node.exc, nodes.Name)
37            and node.exc.name != containing_except_node.name.name
38        ):
39            # We have a `raise SomeException(whatever)` or a `raise SomeException`
40            self.add_message(
41                "raise-missing-from",
42                node=node,
43                args=("", node.as_string(), containing_except_node.name.name),
44                confidence=HIGH,
45            )