Skip to content

Commit cb8ee3b

Browse files
committed
Add ruff rules PIE
1 parent dd24396 commit cb8ee3b

File tree

8 files changed

+12
-19
lines changed

8 files changed

+12
-19
lines changed

news/13426.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ruff rules PIE for minor optimizations to avoid repeated calls to str.startswith and str.endswith.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,17 @@ select = [
178178
"C90",
179179
"E",
180180
"F",
181+
"FA",
181182
"G",
182183
"I",
183184
"ISC",
184185
"PERF",
186+
"PIE",
185187
"PLE",
186188
"PLR0",
187-
"W",
188189
"RUF100",
189190
"UP",
190-
"FA",
191+
"W",
191192
]
192193

193194
[tool.ruff.lint.isort]

src/pip/_internal/operations/freeze.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def freeze(
8686
yield line
8787
continue
8888

89-
if line.startswith("-e") or line.startswith("--editable"):
89+
if line.startswith(("-e", "--editable")):
9090
if line.startswith("-e"):
9191
line = line[2:].strip()
9292
else:

src/pip/_internal/req/req_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def break_args_options(line: str) -> tuple[str, str]:
456456
args = []
457457
options = tokens[:]
458458
for token in tokens:
459-
if token.startswith("-") or token.startswith("--"):
459+
if token.startswith(("-", "--")):
460460
break
461461
else:
462462
args.append(token)

src/pip/_internal/utils/unpacking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def unzip_file(filename: str, location: str, flatten: bool = True) -> None:
133133
"outside target directory ({})"
134134
)
135135
raise InstallationError(message.format(filename, fn, location))
136-
if fn.endswith("/") or fn.endswith("\\"):
136+
if fn.endswith(("/", "\\")):
137137
# A directory
138138
ensure_dir(fn)
139139
else:

src/pip/_internal/vcs/subversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _get_svn_url_rev(cls, location: str) -> tuple[str | None, int]:
140140
data = ""
141141

142142
url = None
143-
if data.startswith("8") or data.startswith("9") or data.startswith("10"):
143+
if data.startswith(("8", "9", "10")):
144144
entries = list(map(str.splitlines, data.split("\n\x0c\n")))
145145
del entries[0][0] # get rid of the '8'
146146
url = entries[0][3]

tests/conftest.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ def pytest_collection_modifyitems(config: Config, items: list[pytest.Function])
122122
)
123123

124124
module_root_dir = module_path.split(os.pathsep)[0]
125-
if (
126-
module_root_dir.startswith("functional")
127-
or module_root_dir.startswith("integration")
128-
or module_root_dir.startswith("lib")
129-
):
125+
if module_root_dir.startswith(("functional", "integration", "lib")):
130126
item.add_marker(pytest.mark.integration)
131127
elif module_root_dir.startswith("unit"):
132128
item.add_marker(pytest.mark.unit)
@@ -503,10 +499,7 @@ def virtualenv_template(
503499

504500
# Drop (non-relocatable) launchers.
505501
for exe in os.listdir(venv.bin):
506-
if not (
507-
exe.startswith("python")
508-
or exe.startswith("libpy") # Don't remove libpypy-c.so...
509-
):
502+
if not exe.startswith(("python", "libpy")): # Don't remove libpypy-c.so...
510503
(venv.bin / exe).unlink()
511504

512505
# Rename original virtualenv directory to make sure

tests/lib/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ def _check_stderr(
462462
# sent directly to stderr and so bypass any configured log formatter.
463463
# The "--- Logging error ---" string is used in Python 3.4+, and
464464
# "Logged from file " is used in Python 2.
465-
if line.startswith("--- Logging error ---") or line.startswith(
466-
"Logged from file "
467-
):
465+
if line.startswith(("--- Logging error ---", "Logged from file ")):
468466
reason = "stderr has a logging error, which is never allowed"
469467
msg = make_check_stderr_message(stderr, line=line, reason=reason)
470468
raise RuntimeError(msg)
@@ -595,7 +593,7 @@ def __init__(
595593
self.user_site_path.joinpath("easy-install.pth").touch()
596594

597595
def _ignore_file(self, fn: str) -> bool:
598-
if fn.endswith("__pycache__") or fn.endswith(".pyc"):
596+
if fn.endswith(("__pycache__", ".pyc")):
599597
result = True
600598
elif self.zipapp and fn.endswith("cacert.pem"):
601599
# Temporary copies of cacert.pem are extracted

0 commit comments

Comments
 (0)