Skip to content

Commit 096cdfd

Browse files
authored
Improve linting. (#586)
1 parent 9c4d7d0 commit 096cdfd

File tree

6 files changed

+19
-28
lines changed

6 files changed

+19
-28
lines changed

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ extend-include = ["*.ipynb"]
112112
[tool.ruff.lint]
113113
select = ["ALL"]
114114
ignore = [
115-
"FBT", # flake8-boolean-trap
116-
"TRY", # ignore tryceratops.
117-
# Others.
118-
"ANN101", # type annotating self
119-
"ANN102", # type annotating cls
115+
"ANN101",
116+
"ANN102",
120117
"ANN401", # flake8-annotate typing.Any
121118
"COM812", # Comply with ruff-format.
122119
"ISC001", # Comply with ruff-format.
120+
"FBT",
123121
"PD901", # Avoid generic df for dataframes.
124122
"S101", # raise errors for asserts.
125123
"S603", # Call check with subprocess.run.

src/_pytask/_inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_annotations( # noqa: C901, PLR0912, PLR0915
106106

107107
if not isinstance(ann, dict):
108108
msg = f"{obj!r}.__annotations__ is neither a dict nor None"
109-
raise ValueError(msg)
109+
raise ValueError(msg) # noqa: TRY004
110110

111111
if not ann:
112112
return {}

src/_pytask/dag_command.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,17 @@ def build_dag(raw_config: dict[str, Any]) -> nx.DiGraph:
188188
session = Session(exit_code=ExitCode.CONFIGURATION_FAILED)
189189

190190
else:
191-
try:
192-
session.hook.pytask_log_session_header(session=session)
193-
import_optional_dependency("pygraphviz")
194-
check_for_optional_program(
195-
session.config["layout"],
196-
extra="The layout program is part of the graphviz package that you "
197-
"can install with conda.",
198-
)
199-
session.hook.pytask_collect(session=session)
200-
session.dag = create_dag(session=session)
201-
session.hook.pytask_unconfigure(session=session)
202-
dag = _refine_dag(session)
203-
204-
except Exception:
205-
raise
206-
207-
else:
208-
return dag
191+
session.hook.pytask_log_session_header(session=session)
192+
import_optional_dependency("pygraphviz")
193+
check_for_optional_program(
194+
session.config["layout"],
195+
extra="The layout program is part of the graphviz package that you "
196+
"can install with conda.",
197+
)
198+
session.hook.pytask_collect(session=session)
199+
session.dag = create_dag(session=session)
200+
session.hook.pytask_unconfigure(session=session)
201+
return _refine_dag(session)
209202

210203

211204
def _refine_dag(session: Session) -> nx.DiGraph:

src/_pytask/path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
]
2626

2727

28-
def relative_to(path: Path, source: Path, include_source: bool = True) -> Path:
28+
def relative_to(path: Path, source: Path, *, include_source: bool = True) -> Path:
2929
"""Make a path relative to another path.
3030
3131
In contrast to :meth:`pathlib.Path.relative_to`, this function allows to keep the
@@ -191,7 +191,7 @@ def _insert_missing_modules(modules: dict[str, ModuleType], module_name: str) ->
191191
# sys.meta_path explicitly and raise the error ourselves to fall back to
192192
# creating a dummy module.
193193
if not sys.meta_path:
194-
raise ModuleNotFoundError
194+
raise ModuleNotFoundError # noqa: TRY301
195195
importlib.import_module(module_name)
196196
except ModuleNotFoundError:
197197
module = ModuleType(

src/_pytask/warnings_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def parse_warning_filter( # noqa: PLR0912, C901
9595
lineno = int(lineno_)
9696
if lineno < 0:
9797
msg = "number is negative"
98-
raise ValueError(msg)
98+
raise ValueError(msg) # noqa: TRY301
9999
except ValueError as e:
100100
raise Exit( # noqa: B904
101101
error_template.format(error=f"invalid lineno {lineno_!r}: {e}")

tests/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
)
3030
def test_relative_to(path, source, include_source, expected):
31-
result = relative_to(path, source, include_source)
31+
result = relative_to(path, source, include_source=include_source)
3232
assert result == expected
3333

3434

0 commit comments

Comments
 (0)