Skip to content

multiple-starts-ends-with

Pythonstyleno fixdefault: offpython/ruff

Reports a.startswith(x) or a.startswith(y) and the same with endswith.

startswith and endswith accept a tuple of prefixes or suffixes, so one call with (x, y) says the same without repeating the name.

To fix, write a.startswith((x, y)).

Reported
...
x = list(a)
x = a.startswith("a") or a.startswith("b")
x = a.endswith("a") or a.endswith(("b", "c")) or c
x = a.startswith("a") or b.startswith("b")
x = a.startswith("a") and a.startswith("b")
x = a.startswith("a") or a.endswith("b")
...
python:
lint:
rules:
multiple-starts-ends-with: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line multiple-starts-ends-with 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 PIE810 full