Skip to content

Simplify Boolean Expressions Using startswith and endswith#107

Open
pixeeai wants to merge 1 commit into
Fanghua-Yu:masterfrom
Pixee-Bot-Python:pixeebot/drip-2024-03-24-pixee-python/combine-startswith-endswith
Open

Simplify Boolean Expressions Using startswith and endswith#107
pixeeai wants to merge 1 commit into
Fanghua-Yu:masterfrom
Pixee-Bot-Python:pixeebot/drip-2024-03-24-pixee-python/combine-startswith-endswith

Conversation

@pixeeai

@pixeeai pixeeai commented Apr 13, 2024

Copy link
Copy Markdown

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

pixeeai commented Apr 14, 2024

Copy link
Copy Markdown
Author

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