An exception object is built as a statement of its own and thrown away
What it finds
ValueError("negative") on a line of its own: the exception is created and dropped, and nothing is raised. raise was left out.
The class must be a builtin exception, or a class of this file, without decorators, that derives from one, directly or through other such classes. A name the file binds in any other way, or imports, is left alone, since it may be a function of the same name. So is a statement directly in the body of a with or try statement, where tests create exceptions with bad arguments to check that this fails.
From the rule's source, unraised_exception.rs.
class AppError(Exception): pass class NotFound(AppError): pass def register(cls): return cls @registerclass Decorated(Exception): pass class Plain: pass def check(n, log): if n < 0: ValueError("negative")tx0 reports: this ValueError is created but not raised if n == 0: NotFound(n)tx0 reports: this NotFound is created but not raised if n == 1: (KeyboardInterrupt())tx0 reports: this KeyboardInterrupt is created but not raised if n == 2: raise ValueError("raised") error = TypeError("kept") log(RuntimeError("passed on")) Decorated() Plain() with log: ValueError(1, 2, invalid=3) try: ValueError(invalid=3) except TypeError: pass return error def shadowed(n): ValueError = print ValueError(n) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:unraised-exception" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:unraised-exception] reason="..."tx0 explain tx0/python:unraised-exception shows the same in the terminal. Found a false positive? Report it.