Skip to content

Add ruff rules PIE810 multiple-starts-ends-with #13426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2025

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Jun 14, 2025

https://docs.astral.sh/ruff/rules/#flake8-pie-pie

Fix eight instances of:
% ruff rule PIE810

The startswith and endswith methods accept tuples of prefixes or suffixes respectively.
Passing a tuple of prefixes or suffixes is more efficient and readable than calling the method multiple times.

References

These transformations to reduce unnecessary repetitive function calls have been recommended since 2006 when they were introduced in Python 2.5

@notatallshaw
Copy link
Member

Thanks for the PR contribution, be aware that maintainer time is limited, so reviews may take a while.

One comment, there’s been some discussion around reducing pip’s exposure to Ruff’s linting rules, especially entire groups that may introduce new rules or change existing ones between releases.

Therefore, I think It would make more sense to only add individual PIE rules with specific justification. Personally, I think PIE810 makes sense to include, but looking through the rest of the rules here: https://docs.astral.sh/ruff/rules/#flake8-pie-pie, none of them stand out to me as having particularly strong justifications. But I'm willing to be persuaded.

@cclauss
Copy link
Contributor Author

cclauss commented Jun 15, 2025

Understood. Given that all other PIE rules already pass on this codebase, I would be OK to only enforcing PIE810.

@uranusjr
Copy link
Member

If all other rules already pass, it’d probably be easier to have one trivial PR to enable all PIE rules except 810, and then another one to enable PIE810.

@notatallshaw
Copy link
Member

If all other rules already pass, it’d probably be easier to have one trivial PR to enable all PIE rules except 810, and then another one to enable PIE810.

I was advocating for not adding the PIE rules as a group, and only adding PIE810 and any other rules which appear to have a strong justification, based on the discussion that happened in this PR #13284.

@cclauss cclauss changed the title Add ruff rules PIE Add ruff rules PIE810 multiple-starts-ends-with Jun 16, 2025
@cclauss
Copy link
Contributor Author

cclauss commented Jun 16, 2025

We now only enforce one rule, not the whole PIE family of rules.

@notatallshaw notatallshaw merged commit f51b434 into pypa:main Jun 21, 2025
29 checks passed
@notatallshaw
Copy link
Member

@cclauss Thanks for your contribution.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants