Skip to content

type-check-without-type-error

Pythonstyleno fixdefault: offpython/ruff

Reports a branch tested with isinstance, issubclass or callable that raises a builtin exception other than TypeError (NotImplementedError is accepted too).

A value of the wrong type is what TypeError means, and callers catch it for that case. A ValueError or Exception there makes them handle a type mistake as a bad value.

To fix, raise TypeError.

Reported
...
...
raise ValueError("x")
...
if x:
...
python:
lint:
rules:
type-check-without-type-error: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line type-check-without-type-error in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff TRY004 full