diff --git a/duties.py b/duties.py index d08b602..5801f5d 100644 --- a/duties.py +++ b/duties.py @@ -117,7 +117,7 @@ def docs(ctx: Context, *cli_args: str, host: str = "127.0.0.1", port: int = 8000 @duty -def docs_deploy(ctx: Context, *, force: bool = False) -> None: +def docs_deploy(ctx: Context, *, force: bool = False) -> None: # noqa: ARG001 """Deploy the documentation to GitHub pages. Parameters: diff --git a/src/failprint/capture.py b/src/failprint/capture.py index 524990e..9f25dee 100644 --- a/src/failprint/capture.py +++ b/src/failprint/capture.py @@ -8,9 +8,10 @@ import tempfile from contextlib import contextmanager from io import StringIO -from typing import IO, TYPE_CHECKING, Iterator, TextIO +from typing import IO, TYPE_CHECKING, TextIO if TYPE_CHECKING: + from collections.abc import Iterator from types import TracebackType @@ -128,7 +129,7 @@ def __enter__(self) -> CaptureManager: # noqa: PYI034 (false-positive) # Open devnull if needed. if self._capture in {Capture.STDOUT, Capture.STDERR}: - self._devnull = open(os.devnull, "w") # noqa: SIM115 + self._devnull = open(os.devnull, "w") # Create temporary file. # Initially we used a pipe but it would hang on writes given enough output. diff --git a/src/failprint/cli.py b/src/failprint/cli.py index 832a967..1c9dd35 100644 --- a/src/failprint/cli.py +++ b/src/failprint/cli.py @@ -15,13 +15,16 @@ import argparse import sys -from typing import Any, Sequence +from typing import TYPE_CHECKING, Any from failprint import debug from failprint.capture import Capture from failprint.formats import accept_custom_format, formats from failprint.runners import run +if TYPE_CHECKING: + from collections.abc import Sequence + class _DebugInfo(argparse.Action): def __init__(self, nargs: int | str | None = 0, **kwargs: Any) -> None: diff --git a/src/failprint/formats.py b/src/failprint/formats.py index 7a52537..46151c8 100644 --- a/src/failprint/formats.py +++ b/src/failprint/formats.py @@ -3,11 +3,12 @@ from __future__ import annotations import inspect -from typing import TYPE_CHECKING, Callable, Sequence +from typing import TYPE_CHECKING, Callable from failprint.lazy import LazyCallable if TYPE_CHECKING: + from collections.abc import Sequence from types import FrameType from failprint.types import CmdFuncType diff --git a/src/failprint/lazy.py b/src/failprint/lazy.py index c4410b1..be1ee06 100644 --- a/src/failprint/lazy.py +++ b/src/failprint/lazy.py @@ -50,13 +50,11 @@ def lazy_caller(*args: _P.args, **kwargs: _P.kwargs) -> LazyCallable: @overload -def lazy(call: Callable[_P, _R], name: str | None = None) -> Callable[_P, LazyCallable]: - ... # pragma: no cover +def lazy(call: Callable[_P, _R], name: str | None = None) -> Callable[_P, LazyCallable]: ... # pragma: no cover @overload -def lazy(call: None = None, name: str | None = None) -> _DecoratorType: - ... # pragma: no cover +def lazy(call: None = None, name: str | None = None) -> _DecoratorType: ... # pragma: no cover def lazy(call: Callable[_P, _R] | None = None, name: str | None = None) -> Callable[_P, LazyCallable] | _DecoratorType: diff --git a/src/failprint/process.py b/src/failprint/process.py index 6dc14cb..f7c11b1 100644 --- a/src/failprint/process.py +++ b/src/failprint/process.py @@ -49,12 +49,12 @@ def run_subprocess( if shell and not isinstance(cmd, str): cmd = printable_command(cmd) - process = subprocess.run( + process = subprocess.run( # noqa: S603 cmd, input=stdin, stdout=stdout_opt, stderr=stderr_opt, - shell=shell, # noqa: S603 + shell=shell, text=True, encoding="utf8", check=False, diff --git a/src/failprint/runners.py b/src/failprint/runners.py index 6d908a5..5394f43 100644 --- a/src/failprint/runners.py +++ b/src/failprint/runners.py @@ -7,7 +7,7 @@ import sys import textwrap import traceback -from typing import TYPE_CHECKING, Callable, Sequence +from typing import TYPE_CHECKING, Callable import colorama from ansimarkup import parse @@ -19,6 +19,8 @@ from failprint.process import WINDOWS, run_pty_subprocess, run_subprocess if TYPE_CHECKING: + from collections.abc import Sequence + from failprint.types import CmdFuncType, CmdType if WINDOWS: diff --git a/src/failprint/types.py b/src/failprint/types.py index e491072..b66afd5 100644 --- a/src/failprint/types.py +++ b/src/failprint/types.py @@ -7,11 +7,11 @@ from __future__ import annotations -from typing import Callable, List, Union +from typing import Callable, Union from failprint.lazy import LazyCallable -CmdType = Union[str, List[str]] +CmdType = Union[str, list[str]] CmdFuncType = Union[CmdType, Callable, LazyCallable] __all__ = ["CmdFuncType", "CmdType"] diff --git a/tests/test_formats.py b/tests/test_formats.py index 9a695b2..5f2fcfa 100644 --- a/tests/test_formats.py +++ b/tests/test_formats.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Callable, Sequence +from typing import TYPE_CHECKING, Callable import pytest from hypothesis import given @@ -11,6 +11,9 @@ from failprint.formats import DEFAULT_CALLABLE_NAME, GT, LT, _get_callable_name, printable_command from failprint.runners import run +if TYPE_CHECKING: + from collections.abc import Sequence + @pytest.mark.parametrize( ("cmd", "expected"), diff --git a/tests/test_lazy.py b/tests/test_lazy.py index 9759e13..3bdb37e 100644 --- a/tests/test_lazy.py +++ b/tests/test_lazy.py @@ -7,16 +7,14 @@ def test_decorating_function() -> None: """Test our `lazy` decorator.""" @lazy - def greet() -> None: - ... # pragma: no cover + def greet() -> None: ... # pragma: no cover non_lazy = greet() assert isinstance(non_lazy, LazyCallable) assert not non_lazy.name @lazy(name="lazy_greet") - def greet2() -> None: - ... # pragma: no cover + def greet2() -> None: ... # pragma: no cover non_lazy = greet2() assert isinstance(non_lazy, LazyCallable) @@ -26,8 +24,7 @@ def greet2() -> None: def test_lazifying_function() -> None: """Test our `lazy` decorator as a function.""" - def greet() -> None: - ... # pragma: no cover + def greet() -> None: ... # pragma: no cover lazy_greet = lazy(greet) non_lazy = lazy_greet()