NotImplemented is raised instead of NotImplementedError

tx0/python:raise-not-implementeddefaultwarningbug

What it finds

raise NotImplemented: NotImplemented is the value binary operators return to let the other operand try, not an exception. Raising it, or calling it, fails with a TypeError that hides what was meant: NotImplementedError. The name must refer to the builtin.

The fix writes NotImplementedError. It is unsafe only in that the raised exception changes, which is the point.

From the rule's source, raise_not_implemented.rs.

Example from the rule's tests
class Shape:    def area(self):        raise NotImplementedtx0 reports: NotImplemented is not an exception; raise NotImplementedError     def perimeter(self):        raise NotImplemented("subclasses define this")tx0 reports: raise NotImplementedError     def scale(self, factor):        raise NotImplementedError     def __eq__(self, other):        return NotImplemented  def shadowed(NotImplemented):    raise NotImplemented
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/python:raise-not-implemented" = "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:raise-not-implemented] reason="..."

tx0 explain tx0/python:raise-not-implemented shows the same in the terminal. Found a false positive? Report it.