astral-sh / astral-sh/ruff

Improve multiple-starts-ends-with (PIE810) to include `any(s.startswith..` ?

Open
#25,232 0 comments 0 reactions 0 assignees View on GitHub
rule
Dominant language
Rust
Stars
49.7k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

### Summary

I recently found a bunch of places in our codebase that were doing things like `any(s.startswith(prefix) for prefix in ('x', 'y'))` which is better written as just `s.startswith(('x', 'y'))`.

See https://github.com/emscripten-core/emscripten/pull/26970

We use ruff but it doesn't seem to currently have suggestion for this.

Would we extend this existing rule perhaps: https://docs.astral.sh/ruff/rules/multiple-starts-ends-with/#multiple-starts-ends-with-pie810

Contributor guide

Open the contributing guide

Research direction

Start with the existing PIE810 rule and its documentation, then trace how Ruff represents the any(s.startswith(...)) pattern. Done means the rule suggests s.startswith(('x', 'y')) for the reported form and documents the behavior consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.