---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:26:5
   |
24 | # Test case 1: Useless exception statement
25 | def func():
26 |     AssertionError("This is an assertion error")  # PLW0133
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27 |     MyError("This is a custom error")  # PLW0133
28 |     MySubError("This is a custom error")  # PLW0133
   |
help: Add `raise` keyword
   |
25 | def func():
   -     AssertionError("This is an assertion error")  # PLW0133
26 +     raise AssertionError("This is an assertion error")  # PLW0133
27 |     MyError("This is a custom error")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:35:9
   |
33 | def func():
34 |     try:
35 |         Exception("This is an exception")  # PLW0133
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36 |         MyError("This is an exception")  # PLW0133
37 |         MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
34 |     try:
   -         Exception("This is an exception")  # PLW0133
35 +         raise Exception("This is an exception")  # PLW0133
36 |         MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:46:9
   |
44 | def func():
45 |     if True:
46 |         RuntimeError("This is an exception")  # PLW0133
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47 |         MyError("This is an exception")  # PLW0133
48 |         MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
45 |     if True:
   -         RuntimeError("This is an exception")  # PLW0133
46 +         raise RuntimeError("This is an exception")  # PLW0133
47 |         MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:56:13
   |
54 |     class Class:
55 |         def __init__(self):
56 |             TypeError("This is an exception")  # PLW0133
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57 |             MyError("This is an exception")  # PLW0133
58 |             MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
55 |         def __init__(self):
   -             TypeError("This is an exception")  # PLW0133
56 +             raise TypeError("This is an exception")  # PLW0133
57 |             MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:65:9
   |
63 | def func():
64 |     def inner():
65 |         IndexError("This is an exception")  # PLW0133
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66 |         MyError("This is an exception")  # PLW0133
67 |         MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
64 |     def inner():
   -         IndexError("This is an exception")  # PLW0133
65 +         raise IndexError("This is an exception")  # PLW0133
66 |         MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:76:9
   |
74 | def func():
75 |     while True:
76 |         KeyError("This is an exception")  # PLW0133
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77 |         MyError("This is an exception")  # PLW0133
78 |         MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
75 |     while True:
   -         KeyError("This is an exception")  # PLW0133
76 +         raise KeyError("This is an exception")  # PLW0133
77 |         MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:87:13
   |
85 |         @abstractmethod
86 |         def method(self):
87 |             NotImplementedError("This is an exception")  # PLW0133
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88 |             MyError("This is an exception")  # PLW0133
89 |             MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
86 |         def method(self):
   -             NotImplementedError("This is an exception")  # PLW0133
87 +             raise NotImplementedError("This is an exception")  # PLW0133
88 |             MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
  --> useless_exception_statement.py:96:9
   |
94 | def func():
95 |     with suppress(Exception):
96 |         AttributeError("This is an exception")  # PLW0133
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97 |         MyError("This is an exception")  # PLW0133
98 |         MySubError("This is an exception")  # PLW0133
   |
help: Add `raise` keyword
   |
95 |     with suppress(Exception):
   -         AttributeError("This is an exception")  # PLW0133
96 +         raise AttributeError("This is an exception")  # PLW0133
97 |         MyError("This is an exception")  # PLW0133
   |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:104:5
    |
102 | # Test case 9: Useless exception statement in parentheses
103 | def func():
104 |     (RuntimeError("This is an exception"))  # PLW0133
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105 |     (MyError("This is an exception"))  # PLW0133
106 |     (MySubError("This is an exception"))  # PLW0133
    |
help: Add `raise` keyword
    |
103 | def func():
    -     (RuntimeError("This is an exception"))  # PLW0133
104 +     raise (RuntimeError("This is an exception"))  # PLW0133
105 |     (MyError("This is an exception"))  # PLW0133
    |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:112:12
    |
110 | # Test case 10: Useless exception statement in continuation
111 | def func():
112 |     x = 1; (RuntimeError("This is an exception")); y = 2  # PLW0133
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113 |     x = 1; (MyError("This is an exception")); y = 2  # PLW0133
114 |     x = 1; (MySubError("This is an exception")); y = 2  # PLW0133
    |
help: Add `raise` keyword
    |
111 | def func():
    -     x = 1; (RuntimeError("This is an exception")); y = 2  # PLW0133
112 +     x = 1; raise (RuntimeError("This is an exception")); y = 2  # PLW0133
113 |     x = 1; (MyError("This is an exception")); y = 2  # PLW0133
    |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:120:5
    |
118 | # Test case 11: Useless warning statement
119 | def func():
120 |     UserWarning("This is a user warning")  # PLW0133
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121 |     MyUserWarning("This is a custom user warning")  # PLW0133
    |
help: Add `raise` keyword
    |
119 | def func():
    -     UserWarning("This is a user warning")  # PLW0133
120 +     raise UserWarning("This is a user warning")  # PLW0133
121 |     MyUserWarning("This is a custom user warning")  # PLW0133
    |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:127:1
    |
125 | import builtins
126 |
127 | builtins.TypeError("still an exception even though it's an Attribute")  # PLW0133
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128 |
129 | PythonFinalizationError("Added in Python 3.13")  # PLW0133
    |
help: Add `raise` keyword
    |
126 |
    - builtins.TypeError("still an exception even though it's an Attribute")  # PLW0133
127 + raise builtins.TypeError("still an exception even though it's an Attribute")  # PLW0133
128 |
    |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:129:1
    |
127 | builtins.TypeError("still an exception even though it's an Attribute")  # PLW0133
128 |
129 | PythonFinalizationError("Added in Python 3.13")  # PLW0133
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130 |
131 | MyError("This is an exception")  # PLW0133
    |
help: Add `raise` keyword
    |
128 |
    - PythonFinalizationError("Added in Python 3.13")  # PLW0133
129 + raise PythonFinalizationError("Added in Python 3.13")  # PLW0133
130 |
    |
note: This is an unsafe fix and may change runtime behavior

PLW0133 [*] Missing `raise` statement on exception
   --> useless_exception_statement.py:137:1
    |
135 | MyValueError("This is an exception")  # PLW0133
136 |
137 | UserWarning("This is a user warning")  # PLW0133
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138 |
139 | MyUserWarning("This is a custom user warning")  # PLW0133
    |
help: Add `raise` keyword
    |
136 |
    - UserWarning("This is a user warning")  # PLW0133
137 + raise UserWarning("This is a user warning")  # PLW0133
138 |
    |
note: This is an unsafe fix and may change runtime behavior
