mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00

## Summary Fixes #9663 and also improves the fixes for [RUF055](https://docs.astral.sh/ruff/rules/unnecessary-regular-expression/) since regular expressions are often written as raw strings. This doesn't include raw f-strings. ## Test Plan Existing snapshots for RUF055 and PT009, plus a new `Generator` test and a regression test for the reported `PIE810` issue.
84 lines
1.8 KiB
Python
84 lines
1.8 KiB
Python
# error
|
|
obj.startswith("foo") or obj.startswith("bar")
|
|
# error
|
|
obj.endswith("foo") or obj.endswith("bar")
|
|
# error
|
|
obj.startswith(foo) or obj.startswith(bar)
|
|
# error
|
|
obj.startswith(foo) or obj.startswith("foo")
|
|
# error
|
|
obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
x = "h"
|
|
y = ("h", "e", "l", "l", "o")
|
|
z = "w"
|
|
|
|
if msg.startswith(x) or msg.startswith(y) or msg.startswith(z): # Error
|
|
print("yes")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
if msg.startswith(("h", "e", "l", "l", "o")) or msg.startswith("h") or msg.startswith("w"): # Error
|
|
print("yes")
|
|
|
|
# ok
|
|
obj.startswith(("foo", "bar"))
|
|
# ok
|
|
obj.endswith(("foo", "bar"))
|
|
# ok
|
|
obj.startswith("foo") or obj.endswith("bar")
|
|
# ok
|
|
obj.startswith("foo") or abc.startswith("bar")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
x = "h"
|
|
y = ("h", "e", "l", "l", "o")
|
|
|
|
if msg.startswith(x) or msg.startswith(y): # OK
|
|
print("yes")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
y = ("h", "e", "l", "l", "o")
|
|
|
|
if msg.startswith(y): # OK
|
|
print("yes")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
y = ("h", "e", "l", "l", "o")
|
|
|
|
if msg.startswith(y) or msg.startswith(y): # OK
|
|
print("yes")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
y = ("h", "e", "l", "l", "o")
|
|
x = ("w", "o", "r", "l", "d")
|
|
|
|
if msg.startswith(y) or msg.startswith(x) or msg.startswith("h"): # OK
|
|
print("yes")
|
|
|
|
def func():
|
|
msg = "hello world"
|
|
|
|
y = ("h", "e", "l", "l", "o")
|
|
x = ("w", "o", "r", "l", "d")
|
|
|
|
if msg.startswith(y) or msg.endswith(x) or msg.startswith("h"): # OK
|
|
print("yes")
|
|
|
|
|
|
def func():
|
|
"Regression test for https://github.com/astral-sh/ruff/issues/9663"
|
|
if x.startswith("a") or x.startswith("b") or re.match(r"a\.b", x):
|
|
print("yes")
|