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 #3

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

Conversation

pixeebot[bot]
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

0 participants