Skip to content

Commit d440aec

Browse files
authored
Add refurb to pre-commit hooks. (#311)
1 parent c3948db commit d440aec

26 files changed

+63
-59
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ repos:
7272
pydocstyle,
7373
Pygments,
7474
]
75+
- repo: https://github.com/dosisod/refurb
76+
rev: v1.5.0
77+
hooks:
78+
- id: refurb
79+
args: [--ignore, FURB126]
80+
language_version: python3.10
7581
- repo: https://github.com/executablebooks/mdformat
7682
rev: 0.7.16
7783
hooks:

src/_pytask/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _collect_all_paths_known_to_pytask(session: Session) -> set[Path]:
223223
def _yield_paths_from_task(task: Task) -> Generator[Path, None, None]:
224224
"""Yield all paths attached to a task."""
225225
yield task.path
226-
for attribute in ["depends_on", "produces"]:
226+
for attribute in ("depends_on", "produces"):
227227
for node in tree_just_yield(getattr(task, attribute)):
228228
if hasattr(node, "path") and isinstance(node.path, Path):
229229
yield node.path

src/_pytask/click.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def print_options(group_or_command: click.Command | DefaultGroup, ctx: Any) -> N
118118
elif len(param.opts) == 2:
119119
opt1 = highlighter(param.opts[0])
120120
opt2 = highlighter(param.opts[1])
121-
elif len(param.opts) == 1 and len(param.secondary_opts) == 1:
121+
elif len(param.opts) == 1 == len(param.secondary_opts):
122122
opt1 = Text("")
123123
opt2 = highlighter(param.opts[0] + "/" + param.secondary_opts[0])
124124
else:

src/_pytask/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def _find_project_root_and_config(paths: list[Path]) -> tuple[Path, Path]:
284284
parent_directories = [common_ancestor] + list(common_ancestor.parents)
285285

286286
for parent in parent_directories:
287-
for config_name in ["pyproject.toml", "pytask.ini", "tox.ini", "setup.cfg"]:
287+
for config_name in ("pyproject.toml", "pytask.ini", "tox.ini", "setup.cfg"):
288288

289289
path = parent.joinpath(config_name)
290290

src/_pytask/config_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_click_choice(
1818
value_to_name = {enum_[name].value: name for name in enum_.__members__}
1919

2020
def _parse(x: Enum | str | None) -> Enum | None:
21-
if x in [None, "None", "none"]:
21+
if x in (None, "None", "none"):
2222
out = None
2323
elif isinstance(x, str) and x in value_to_name:
2424
out = enum_[value_to_name[x]]

src/_pytask/debugging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def _pdbcls_callback(x: str | None) -> tuple[str, str] | None:
9797
"""Validate the debugger class string passed to pdbcls."""
9898
message = "'pdbcls' must be like IPython.terminal.debugger:TerminalPdb"
9999

100-
if x in [None, "None", "none"]:
100+
if x in (None, "None", "none"):
101101
return None
102102
elif isinstance(x, str):
103103
if len(x.split(":")) != 2:

src/_pytask/live.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def pytask_parse_config(
5959

6060
def _parse_n_entries_in_table(value: int | str | None) -> int:
6161
"""Parse how many entries should be displayed in the table during the execution."""
62-
if value in ["none", "None", None, ""]:
62+
if value in ("none", "None", None, ""):
6363
out = None
6464
elif isinstance(value, int) and value >= 1:
6565
out = value

src/_pytask/logging.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def pytask_parse_config(
6464
config_from_file,
6565
key="editor_url_scheme",
6666
default="file",
67-
callback=lambda x: None if x in [None, "none", "None"] else str(x),
67+
callback=lambda x: None if x in (None, "none", "None") else str(x),
6868
)
69-
if config["editor_url_scheme"] not in ["no_link", "file"] and IS_WINDOWS_TERMINAL:
69+
if config["editor_url_scheme"] not in ("no_link", "file") and IS_WINDOWS_TERMINAL:
7070
config["editor_url_scheme"] = "file"
7171
warnings.warn(
7272
"Windows Terminal does not support url schemes to applications, yet."
@@ -145,9 +145,9 @@ def _format_duration(duration: float) -> str:
145145
duration_tuples = _humanize_time(duration, "seconds", short_label=False)
146146

147147
# Remove seconds if the execution lasted days or hours.
148-
if duration_tuples[0][1] in ["day", "days", "hour", "hours"]:
148+
if duration_tuples[0][1] in ("day", "days", "hour", "hours"):
149149
duration_tuples = [
150-
i for i in duration_tuples if i[1] not in ["second", "seconds"]
150+
i for i in duration_tuples if i[1] not in ("second", "seconds")
151151
]
152152

153153
formatted_duration = ", ".join([" ".join(map(str, i)) for i in duration_tuples])
@@ -177,7 +177,7 @@ def _humanize_time(
177177
"""
178178
index = None
179179
for i, time_unit in enumerate(_TIME_UNITS):
180-
if unit in [time_unit.singular, time_unit.plural]:
180+
if unit in (time_unit.singular, time_unit.plural):
181181
index = i
182182
break
183183
else:

src/_pytask/mark/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _read_marker_mapping(x: dict[str, str] | str) -> dict[str, str]:
137137
mapping = {k.strip(): "" for k in x}
138138
elif isinstance(x, str):
139139
# Split by newlines and remove empty strings.
140-
lines = filter(lambda i: bool(i), x.split("\n"))
140+
lines = filter(bool, x.split("\n"))
141141
mapping = {}
142142
for line in lines:
143143
try:

src/_pytask/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def __getattr__(self, name: str) -> MarkDecorator | Any:
196196
if self.config["strict_markers"]:
197197
raise ValueError(f"Unknown pytask.mark.{name}.")
198198
# Raise a specific error for common misspellings of "parametrize".
199-
if name in ["parameterize", "parametrise", "parameterise"]:
199+
if name in ("parameterize", "parametrise", "parameterise"):
200200
warnings.warn(f"Unknown {name!r} mark, did you mean 'parametrize'?")
201201

202202
warnings.warn(

0 commit comments

Comments
 (0)