Skip to content

Commit 9bdf2c3

Browse files
[pre-commit.ci] pre-commit autoupdate (#778)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tobias Raabe <raabe@posteo.de>
1 parent dfd17ce commit 9bdf2c3

5 files changed

Lines changed: 41 additions & 27 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
- id: python-no-log-warn
2626
- id: text-unicode-replacement-char
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
28-
rev: v0.14.14
28+
rev: v0.15.0
2929
hooks:
3030
- id: ruff-format
3131
- id: ruff-check

src/_pytask/collect_command.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def _print_collected_tasks(
200200
for node in sorted(
201201
deps,
202202
key=(
203-
lambda x: x.path.as_posix()
204-
if isinstance(x, PPathNode)
205-
else x.name
203+
lambda x: (
204+
x.path.as_posix() if isinstance(x, PPathNode) else x.name
205+
)
206206
),
207207
):
208208
text = format_node_name(node, (common_ancestor,))
@@ -211,9 +211,9 @@ def _print_collected_tasks(
211211
products: list[Any] = list(tree_leaves(task.produces))
212212
for node in sorted(
213213
products,
214-
key=lambda x: x.path.as_posix()
215-
if isinstance(x, PPathNode)
216-
else x.name,
214+
key=lambda x: (
215+
x.path.as_posix() if isinstance(x, PPathNode) else x.name
216+
),
217217
):
218218
text = format_node_name(node, (common_ancestor,))
219219
task_branch.add(Text.assemble(FILE_ICON, "<Product ", text, ">"))

src/_pytask/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def import_optional_dependency(
9999
return None
100100

101101
# Handle submodules: if we have submodule, grab parent module from sys.modules
102-
parent = name.split(".")[0]
102+
parent = name.split(".", maxsplit=1)[0]
103103
if parent != name:
104104
install_name = parent
105105
module_to_get = sys.modules[install_name]

src/_pytask/dag.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ def _add_product(
9595
# another task that is a dependency in the current task. Thus, draw an edge
9696
# connecting the two nodes.
9797
tree_map(
98-
lambda x: dag.add_edge(x.value.signature, x.signature)
99-
if isinstance(x, PythonNode) and isinstance(x.value, PythonNode)
100-
else None,
98+
lambda x: (
99+
dag.add_edge(x.value.signature, x.signature)
100+
if isinstance(x, PythonNode) and isinstance(x.value, PythonNode)
101+
else None
102+
),
101103
task.depends_on,
102104
)
103105
return dag

tests/test_capture.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import textwrap
99
from io import UnsupportedOperation
1010
from typing import TYPE_CHECKING
11+
from typing import Any
1112
from typing import BinaryIO
13+
from typing import cast
1214

1315
import pytest
1416

@@ -208,7 +210,8 @@ def test_init_capturing(self):
208210
try:
209211
capman = CaptureManager(CaptureMethod.FD)
210212
capman.start_capturing()
211-
pytest.raises(AssertionError, capman.start_capturing)
213+
with pytest.raises(AssertionError):
214+
capman.start_capturing()
212215
capman.stop_capturing()
213216
finally:
214217
capouter.stop_capturing()
@@ -364,7 +367,8 @@ def test_text(self):
364367
def test_unicode_and_str_mixture(self):
365368
f = capture.CaptureIO()
366369
f.write("\u00f6")
367-
pytest.raises(TypeError, f.write, b"hello")
370+
with pytest.raises(TypeError):
371+
f.write(cast("Any", b"hello"))
368372

369373
def test_write_bytes_to_buffer(self):
370374
"""In python3, stdout / stderr are text io wrappers (exposing a buffer property
@@ -394,7 +398,8 @@ def test_unicode_and_str_mixture(self):
394398
sio = io.StringIO()
395399
f = capture.TeeCaptureIO(sio)
396400
f.write("\u00f6")
397-
pytest.raises(TypeError, f.write, b"hello")
401+
with pytest.raises(TypeError):
402+
f.write(cast("Any", b"hello"))
398403

399404

400405
def test_dontreadfrominput():
@@ -403,11 +408,15 @@ def test_dontreadfrominput():
403408
f = DontReadFromInput()
404409
assert f.buffer is f
405410
assert not f.isatty()
406-
pytest.raises(OSError, f.read)
407-
pytest.raises(OSError, f.readlines)
411+
with pytest.raises(OSError):
412+
f.read()
413+
with pytest.raises(OSError):
414+
f.readlines()
408415
iter_f = iter(f)
409-
pytest.raises(OSError, next, iter_f)
410-
pytest.raises(UnsupportedOperation, f.fileno)
416+
with pytest.raises(OSError):
417+
next(iter_f)
418+
with pytest.raises(UnsupportedOperation):
419+
f.fileno()
411420
f.close() # just for completeness
412421

413422

@@ -474,7 +483,8 @@ def test_simple(self, tmpfile):
474483
cap = capture.FDCapture(fd)
475484
data = b"hello"
476485
os.write(fd, data)
477-
pytest.raises(AssertionError, cap.snap)
486+
with pytest.raises(AssertionError):
487+
cap.snap()
478488
cap.done()
479489
cap = capture.FDCapture(fd)
480490
cap.start()
@@ -495,7 +505,8 @@ def test_simple_fail_second_start(self, tmpfile):
495505
fd = tmpfile.fileno()
496506
cap = capture.FDCapture(fd)
497507
cap.done()
498-
pytest.raises(AssertionError, cap.start)
508+
with pytest.raises(AssertionError):
509+
cap.start()
499510

500511
def test_stderr(self):
501512
cap = capture.FDCapture(2)
@@ -546,7 +557,8 @@ def test_simple_resume_suspend(self):
546557
assert s == "but now yes\n"
547558
cap.suspend()
548559
cap.done()
549-
pytest.raises(AssertionError, cap.suspend)
560+
with pytest.raises(AssertionError):
561+
cap.suspend()
550562

551563
assert repr(cap) == (
552564
"<FDCapture 1 oldfd={} _state='done' tmpfile={!r}>".format( # noqa: UP032
@@ -631,7 +643,8 @@ def test_reset_twice_error(self):
631643
with self.getcapture() as cap:
632644
print("hello")
633645
out, err = cap.readouterr()
634-
pytest.raises(ValueError, cap.stop_capturing)
646+
with pytest.raises(ValueError):
647+
cap.stop_capturing()
635648
assert out == "hello\n"
636649
assert not err
637650

@@ -688,8 +701,8 @@ def test_stdin_nulled_by_default(self):
688701
print("XX this test may well hang instead of crashing")
689702
print("XX which indicates an error in the underlying capturing")
690703
print("XX mechanisms")
691-
with self.getcapture():
692-
pytest.raises(OSError, sys.stdin.read)
704+
with self.getcapture(), pytest.raises(OSError):
705+
sys.stdin.read()
693706

694707

695708
class TestTeeStdCapture(TestStdCapture):
@@ -829,6 +842,5 @@ def test_fdcapture_invalid_fd_without_fd_reuse(self, tmp_path):
829842

830843
def test__get_multicapture() -> None:
831844
assert isinstance(_get_multicapture(CaptureMethod.NO), MultiCapture)
832-
pytest.raises(ValueError, _get_multicapture, "unknown").match(
833-
r"^unknown capturing method: 'unknown'"
834-
)
845+
with pytest.raises(ValueError, match=r"^unknown capturing method: 'unknown'"):
846+
_get_multicapture(cast("CaptureMethod", "unknown"))

0 commit comments

Comments
 (0)