Skip to content

Commit 88fb767

Browse files
Skylion007x612skm
authored andcommitted
Enable ruff FURB188: str.remove(pre|suf)fix (python#18671)
1 parent dcc4f30 commit 88fb767

File tree

6 files changed

+9
-15
lines changed

6 files changed

+9
-15
lines changed

misc/upload-pypi.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ def item_ok_for_pypi(name: str) -> bool:
3434
if not is_whl_or_tar(name):
3535
return False
3636

37-
if name.endswith(".tar.gz"):
38-
name = name[:-7]
39-
if name.endswith(".whl"):
40-
name = name[:-4]
37+
name = name.removesuffix(".tar.gz")
38+
name = name.removesuffix(".whl")
4139

4240
if name.endswith("wasm32"):
4341
return False
@@ -123,8 +121,7 @@ def upload_to_pypi(version: str, dry_run: bool = True) -> None:
123121
assert re.match(r"v?[1-9]\.[0-9]+\.[0-9](\+\S+)?$", version)
124122
if "dev" in version:
125123
assert dry_run, "Must use --dry-run with dev versions of mypy"
126-
if version.startswith("v"):
127-
version = version[1:]
124+
version = version.removeprefix("v")
128125

129126
target_dir = tempfile.mkdtemp()
130127
dist = Path(target_dir) / "dist"

mypy/find_sources.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def _crawl_up_helper(self, dir: str) -> tuple[str, str] | None:
176176
return "", dir
177177

178178
parent, name = os.path.split(dir)
179-
if name.endswith("-stubs"):
180-
name = name[:-6] # PEP-561 stub-only directory
179+
name = name.removesuffix("-stubs") # PEP-561 stub-only directory
181180

182181
# recurse if there's an __init__.py
183182
init_file = self.get_init_file(dir)

mypy/stubtest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def _verify_arg_name(
641641
return
642642

643643
def strip_prefix(s: str, prefix: str) -> str:
644-
return s[len(prefix) :] if s.startswith(prefix) else s
644+
return s.removeprefix(prefix)
645645

646646
if strip_prefix(stub_arg.variable.name, "__") == runtime_arg.name:
647647
return

mypy/test/helpers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ def check_test_output_files(
413413
testcase: DataDrivenTestCase, step: int, strip_prefix: str = ""
414414
) -> None:
415415
for path, expected_content in testcase.output_files:
416-
if path.startswith(strip_prefix):
417-
path = path[len(strip_prefix) :]
416+
path = path.removeprefix(strip_prefix)
418417
if not os.path.exists(path):
419418
raise AssertionError(
420419
"Expected file {} was not produced by test case{}".format(

mypyc/irbuild/ll_builder.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13451345
return self.translate_instance_contains(rreg, lreg, op, line)
13461346
if is_fixed_width_rtype(ltype):
13471347
if op in FIXED_WIDTH_INT_BINARY_OPS:
1348-
if op.endswith("="):
1349-
op = op[:-1]
1348+
op = op.removesuffix("=")
13501349
if op != "//":
13511350
op_id = int_op_to_id[op]
13521351
else:
@@ -1372,8 +1371,7 @@ def binary_op(self, lreg: Value, rreg: Value, op: str, line: int) -> Value:
13721371
return self.comparison_op(lreg, self.coerce(rreg, ltype, line), op_id, line)
13731372
elif is_fixed_width_rtype(rtype):
13741373
if op in FIXED_WIDTH_INT_BINARY_OPS:
1375-
if op.endswith("="):
1376-
op = op[:-1]
1374+
op = op.removesuffix("=")
13771375
if op != "//":
13781376
op_id = int_op_to_id[op]
13791377
else:

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ select = [
143143
"UP", # pyupgrade
144144
"C4", # flake8-comprehensions
145145
"SIM201", "SIM202", "SIM222", "SIM223", # flake8-simplify
146+
"FURB188", # use str.remove(pre|suf)fix
146147
"ISC001", # implicitly concatenated string
147148
"RET501", "RET502", # better return None handling
148149
]

0 commit comments

Comments
 (0)