Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simplify Boolean Expressions Using startswith and endswith #3

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

Open
pixeebot wants to merge 1 commit into master
base: master
Choose a base branch
Loading
from pixeebot/drip-2024年03月27日-pixee-python/combine-startswith-endswith

Conversation

Copy link

@pixeebot pixeebot bot commented Mar 27, 2024

Many developers are not necessarily aware that the startswith and endswith methods of str objects can accept a tuple of strings to match. This means that there is a lot of code that uses boolean expressions such as x.startswith('foo') or x.startswith('bar') instead of the simpler expression x.startswith(('foo', 'bar')).

This codemod simplifies the boolean expressions where possible which leads to cleaner and more concise code.

The changes from this codemod look like this:

 x = 'foo'
- if x.startswith("foo") or x.startswith("bar"):
+ if x.startswith(("foo", "bar")):
 ...

Powered by: pixeebot (codemod ID: pixee:python/combine-startswith-endswith)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

0 participants

AltStyle によって変換されたページ (->オリジナル) /