Skip to content
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

Simplify Boolean Expressions Using startswith and endswith #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pixeeai
Copy link

@pixeeai pixeeai commented Apr 13, 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)

@pixeeai
Copy link
Author

pixeeai commented Apr 14, 2024

FYI - This change was autogenerated from a new trending GitHub app - called Pixeebot. A code-quality GitHub App; like Dependabot, but for source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant