From 6ca8d9bf6f6613d31bd0277c90d322001a9bca34 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:07:38 -0700 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#3091) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/check.yml | 3 +- .pre-commit-config.yaml | 6 +-- pyproject.toml | 27 +++++----- src/tox/config/cli/parser.py | 7 +-- src/tox/config/loader/api.py | 10 ++-- src/tox/config/loader/convert.py | 9 +--- src/tox/config/loader/ini/replace.py | 2 +- src/tox/config/loader/section.py | 14 ++++-- src/tox/config/of_type.py | 17 ++++--- src/tox/config/types.py | 17 ++++--- .../local_sub_process/read_via_thread.py | 9 +++- src/tox/execute/stream.py | 8 ++- src/tox/provision.py | 6 +-- src/tox/pytest.py | 50 ++++++++----------- src/tox/session/cmd/run/single.py | 6 +-- src/tox/session/env_select.py | 8 +-- .../python/virtual_env/package/cmd_builder.py | 6 +-- .../python/virtual_env/package/pyproject.py | 5 +- tests/config/loader/ini/replace/conftest.py | 6 +-- tests/config/loader/test_str_convert.py | 5 +- tests/config/test_set_env.py | 6 +-- tests/conftest.py | 18 ++----- tests/demo_pkg_inline/build.py | 17 +++---- .../local_subprocess/test_local_subprocess.py | 10 ++-- tests/test_provision.py | 5 +- .../python/virtual_env/package/conftest.py | 4 +- .../package/test_python_package_util.py | 5 +- tox.ini | 4 +- 28 files changed, 127 insertions(+), 163 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 033d827d6..98521a5ee 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -18,12 +18,11 @@ jobs: fail-fast: false matrix: py: - - "3.12.0-beta.2" + - "3.12.0-rc.1" - "3.11" - "3.10" - "3.9" - "3.8" - - "3.7" os: - ubuntu-latest - windows-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 195c708ac..fe009ad36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,10 +14,10 @@ repos: - id: tox-ini-fmt args: ["-p", "fix"] - repo: https://github.com/tox-dev/pyproject-fmt - rev: "0.13.0" + rev: "0.13.1" hooks: - id: pyproject-fmt - additional_dependencies: ["tox>=4.6.4"] + additional_dependencies: ["tox>=4.8"] - repo: https://github.com/pre-commit/mirrors-prettier rev: "v3.0.1" hooks: @@ -29,7 +29,7 @@ repos: - id: blacken-docs additional_dependencies: [black==23.7] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.0.282" + rev: "v0.0.284" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/pyproject.toml b/pyproject.toml index 5ce1823be..f828d07eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ build-backend = "hatchling.build" requires = [ "hatch-vcs>=0.3", - "hatchling>=1.17.1", + "hatchling>=1.18", ] [project] @@ -24,7 +24,7 @@ maintainers = [ { name = "Oliver Bestwalter", email = "oliver@bestwalter.de" }, ] authors = [{ name = "Bernát Gábor", email = "gaborjbernat@gmail.com" }] -requires-python = ">=3.7" +requires-python = ">=3.8" classifiers = [ "Development Status :: 5 - Production/Stable", "Framework :: tox", @@ -34,7 +34,6 @@ classifiers = [ "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -49,23 +48,23 @@ dynamic = [ ] dependencies = [ "cachetools>=5.3.1", - "chardet>=5.1", + "chardet>=5.2", "colorama>=0.4.6", "filelock>=3.12.2", - 'importlib-metadata>=6.7; python_version < "3.8"', + 'importlib-metadata>=6.8; python_version < "3.8"', "packaging>=23.1", - "platformdirs>=3.9.1", + "platformdirs>=3.10", "pluggy>=1.2", "pyproject-api>=1.5.3", 'tomli>=2.0.1; python_version < "3.11"', 'typing-extensions>=4.7.1; python_version < "3.8"', - "virtualenv>=20.24.1", + "virtualenv>=20.24.3", ] optional-dependencies.docs = [ - "furo>=2023.5.20", - "sphinx>=7.0.1", + "furo>=2023.7.26", + "sphinx>=7.1.2", "sphinx-argparse-cli>=1.11.1", - "sphinx-autodoc-typehints!=1.23.4,>=1.23.3", + "sphinx-autodoc-typehints!=1.23.4,>=1.24", "sphinx-copybutton>=0.5.2", "sphinx-inline-tabs>=2023.4.21", "sphinxcontrib-towncrier>=0.2.1a0", @@ -80,15 +79,15 @@ optional-dependencies.testing = [ "distlib>=0.3.7", "flaky>=3.7", "hatch-vcs>=0.3", - "hatchling>=1.17.1", + "hatchling>=1.18", "psutil>=5.9.5", "pytest>=7.4", "pytest-cov>=4.1", "pytest-mock>=3.11.1", "pytest-xdist>=3.3.1", "re-assert>=1.1", - 'time-machine>=2.10; implementation_name != "pypy"', - "wheel>=0.40", + 'time-machine>=2.12; implementation_name != "pypy"', + "wheel>=0.41.1", ] urls.Documentation = "https://tox.wiki" urls.Homepage = "http://tox.readthedocs.org" @@ -109,7 +108,7 @@ line-length = 120 [tool.ruff] select = ["ALL"] line-length = 120 -target-version = "py37" +target-version = "py38" isort = {known-first-party = ["tox", "tests"], required-imports = ["from __future__ import annotations"]} ignore = [ "INP001", # no implicit namespaces here diff --git a/src/tox/config/cli/parser.py b/src/tox/config/cli/parser.py index b06b10ae8..f18561a9d 100644 --- a/src/tox/config/cli/parser.py +++ b/src/tox/config/cli/parser.py @@ -7,7 +7,7 @@ import sys from argparse import SUPPRESS, Action, ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, TypeVar, cast +from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Type, TypeVar, cast from tox.config.loader.str_convert import StrConvert from tox.plugin import NAME @@ -15,11 +15,6 @@ from .env_var import get_env_var from .ini import IniConfig -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Literal -else: # pragma: no cover (py38+) - from typing_extensions import Literal - if TYPE_CHECKING: from tox.session.state import State diff --git a/src/tox/config/loader/api.py b/src/tox/config/loader/api.py index 7bf819996..30af68a75 100644 --- a/src/tox/config/loader/api.py +++ b/src/tox/config/loader/api.py @@ -38,12 +38,16 @@ def __repr__(self) -> str: def __str__(self) -> str: return f"{self.namespace}{'.' if self.namespace else ''}{self.key}={self.value}" - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: if type(self) != type(other): return False - return (self.namespace, self.key, self.value) == (other.namespace, other.key, other.value) + return (self.namespace, self.key, self.value) == ( + other.namespace, # type: ignore[attr-defined] + other.key, # type: ignore[attr-defined] + other.value, # type: ignore[attr-defined] + ) - def __ne__(self, other: Any) -> bool: + def __ne__(self, other: object) -> bool: return not (self == other) diff --git a/src/tox/config/loader/convert.py b/src/tox/config/loader/convert.py index 519314c4c..c85091738 100644 --- a/src/tox/config/loader/convert.py +++ b/src/tox/config/loader/convert.py @@ -1,19 +1,12 @@ from __future__ import annotations -import sys from abc import ABC, abstractmethod from collections import OrderedDict from pathlib import Path -from typing import Any, Callable, Dict, Generic, Iterator, List, Optional, Set, TypeVar, Union, cast +from typing import Any, Callable, Dict, Generic, Iterator, List, Literal, Optional, Set, TypeVar, Union, cast from tox.config.types import Command, EnvList -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Literal -else: # pragma: no cover (py38+) - from typing_extensions import Literal - - _NO_MAPPING = object() T = TypeVar("T") V = TypeVar("V") diff --git a/src/tox/config/loader/ini/replace.py b/src/tox/config/loader/ini/replace.py index f72db8f16..c7e83d93e 100644 --- a/src/tox/config/loader/ini/replace.py +++ b/src/tox/config/loader/ini/replace.py @@ -67,7 +67,7 @@ def __init__(self, expr: Sequence[MatchArg], term_pos: int | None = None) -> Non def __repr__(self) -> str: return f"MatchExpression(expr={self.expr!r}, term_pos={self.term_pos!r})" - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: if isinstance(other, type(self)): return self.expr == other.expr return NotImplemented diff --git a/src/tox/config/loader/section.py b/src/tox/config/loader/section.py index d31665168..778433703 100644 --- a/src/tox/config/loader/section.py +++ b/src/tox/config/loader/section.py @@ -1,8 +1,14 @@ from __future__ import annotations -from typing import Any, TypeVar +from typing import TYPE_CHECKING -_Section = TypeVar("_Section", bound="Section") +if TYPE_CHECKING: + import sys + + if sys.version_info >= (3, 11): # pragma: no cover (py311+) + from typing import Self + else: # pragma: no cover ( None: self._name = name @classmethod - def from_key(cls: type[_Section], key: str) -> _Section: + def from_key(cls: type[Self], key: str) -> Self: """ Create a section from a section key. @@ -50,7 +56,7 @@ def __str__(self) -> str: def __repr__(self) -> str: return f"{self.__class__.__name__}(prefix={self._prefix!r}, name={self._name!r})" - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: return isinstance(other, self.__class__) and (self._prefix, self._name) == ( other._prefix, other.name, diff --git a/src/tox/config/of_type.py b/src/tox/config/of_type.py index 6c01a1231..4f6f47bc9 100644 --- a/src/tox/config/of_type.py +++ b/src/tox/config/of_type.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from itertools import product -from typing import TYPE_CHECKING, Any, Callable, Generic, Iterable, TypeVar, cast +from typing import TYPE_CHECKING, Callable, Generic, Iterable, TypeVar, cast from tox.config.loader.api import ConfigLoadArgs, Loader @@ -27,10 +27,10 @@ def __init__(self, keys: Iterable[str], desc: str) -> None: def __call__(self, conf: Config, loaders: list[Loader[T]], args: ConfigLoadArgs) -> T: raise NotImplementedError - def __eq__(self, o: Any) -> bool: - return type(self) == type(o) and (self.keys, self.desc) == (o.keys, o.desc) + def __eq__(self, o: object) -> bool: + return type(self) == type(o) and (self.keys, self.desc) == (o.keys, o.desc) # type: ignore[attr-defined] - def __ne__(self, o: Any) -> bool: + def __ne__(self, o: object) -> bool: return not (self == o) @@ -54,8 +54,8 @@ def __call__( ) -> T: return self.value() if callable(self.value) else self.value - def __eq__(self, o: Any) -> bool: - return type(self) == type(o) and super().__eq__(o) and self.value == o.value + def __eq__(self, o: object) -> bool: + return type(self) == type(o) and super().__eq__(o) and self.value == o.value # type: ignore[attr-defined] _PLACE_HOLDER = object() @@ -112,11 +112,12 @@ def __repr__(self) -> str: values = ((k, v) for k, v in vars(self).items() if k != "post_process" and v is not None) return f"{type(self).__name__}({', '.join(f'{k}={v}' for k, v in values)})" - def __eq__(self, o: Any) -> bool: + def __eq__(self, o: object) -> bool: return ( type(self) == type(o) and super().__eq__(o) - and (self.of_type, self.default, self.post_process) == (o.of_type, o.default, o.post_process) + and (self.of_type, self.default, self.post_process) + == (o.of_type, o.default, o.post_process) # type: ignore[attr-defined] ) diff --git a/src/tox/config/types.py b/src/tox/config/types.py index 9403e7f4b..7f3e43770 100644 --- a/src/tox/config/types.py +++ b/src/tox/config/types.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections import OrderedDict -from typing import Any, Iterator, Sequence +from typing import Iterator, Sequence from tox.execute.request import shell_cmd @@ -21,10 +21,13 @@ def __init__(self, args: list[str]) -> None: def __repr__(self) -> str: return f"{type(self).__name__}(args={(['-'] if self.ignore_exit_code else [])+ self.args!r})" - def __eq__(self, other: Any) -> bool: - return type(self) == type(other) and (self.args, self.ignore_exit_code) == (other.args, other.ignore_exit_code) + def __eq__(self, other: object) -> bool: + return type(self) == type(other) and (self.args, self.ignore_exit_code) == ( + other.args, # type: ignore[attr-defined] + other.ignore_exit_code, # type: ignore[attr-defined] + ) - def __ne__(self, other: Any) -> bool: + def __ne__(self, other: object) -> bool: return not (self == other) @property @@ -47,10 +50,10 @@ def __init__(self, envs: Sequence[str]) -> None: def __repr__(self) -> str: return f"{type(self).__name__}({self.envs!r})" - def __eq__(self, other: Any) -> bool: - return type(self) == type(other) and self.envs == other.envs + def __eq__(self, other: object) -> bool: + return type(self) == type(other) and self.envs == other.envs # type: ignore[attr-defined] - def __ne__(self, other: Any) -> bool: + def __ne__(self, other: object) -> bool: return not (self == other) def __iter__(self) -> Iterator[str]: diff --git a/src/tox/execute/local_sub_process/read_via_thread.py b/src/tox/execute/local_sub_process/read_via_thread.py index f0dd40db3..3fce53fa2 100644 --- a/src/tox/execute/local_sub_process/read_via_thread.py +++ b/src/tox/execute/local_sub_process/read_via_thread.py @@ -6,8 +6,15 @@ from typing import TYPE_CHECKING, Callable if TYPE_CHECKING: + import sys from types import TracebackType + if sys.version_info >= (3, 11): # pragma: no cover (py311+) + from typing import Self + else: # pragma: no cover ( ReadViaThread: + def __enter__(self) -> Self: self.thread.start() return self diff --git a/src/tox/execute/stream.py b/src/tox/execute/stream.py index 2d3ab3561..ce0125e7c 100644 --- a/src/tox/execute/stream.py +++ b/src/tox/execute/stream.py @@ -7,8 +7,14 @@ from colorama import Fore if TYPE_CHECKING: + import sys from types import TracebackType + if sys.version_info >= (3, 11): # pragma: no cover (py311+) + from typing import Self + else: # pragma: no cover ( str: return f"{self.__class__.__name__}(name={self.name!r}, target={self._target!r}, color={self._color!r})" - def __enter__(self) -> SyncWrite: + def __enter__(self) -> Self: if self._target_enabled: self._start() return self diff --git a/src/tox/provision.py b/src/tox/provision.py index 1b7670602..9e1656a42 100644 --- a/src/tox/provision.py +++ b/src/tox/provision.py @@ -4,6 +4,7 @@ import json import logging import sys +from importlib.metadata import PackageNotFoundError, distribution from pathlib import Path from typing import TYPE_CHECKING, List, cast @@ -19,11 +20,6 @@ from tox.tox_env.python.pip.req_file import PythonDeps from tox.tox_env.python.runner import PythonRun -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from importlib.metadata import PackageNotFoundError, distribution -else: # pragma: no cover (py38+) - from importlib_metadata import PackageNotFoundError, distribution - if TYPE_CHECKING: from argparse import ArgumentParser diff --git a/src/tox/pytest.py b/src/tox/pytest.py index bc6060daf..4c968860b 100644 --- a/src/tox/pytest.py +++ b/src/tox/pytest.py @@ -12,14 +12,10 @@ from contextlib import closing, contextmanager from pathlib import Path from types import ModuleType, TracebackType -from typing import TYPE_CHECKING, Any, Callable, Iterator, Sequence, cast +from typing import TYPE_CHECKING, Any, Callable, Iterator, Protocol, Sequence, cast import pytest -from _pytest.capture import CaptureFixture as _CaptureFixture from _pytest.fixtures import SubRequest -from _pytest.logging import LogCaptureFixture -from _pytest.monkeypatch import MonkeyPatch -from _pytest.tmpdir import TempPathFactory from devpi_process import IndexServer from virtualenv.info import fs_supports_symlink @@ -34,26 +30,18 @@ from tox.tox_env import api as tox_env_api from tox.tox_env.api import ToxEnv -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Protocol -else: # pragma: no cover ( Iterator[None]: @pytest.fixture(autouse=True) -def check_os_environ_stable(monkeypatch: MonkeyPatch) -> Iterator[None]: # noqa: PT004 +def check_os_environ_stable(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: # noqa: PT004 with check_os_environ(): yield monkeypatch.undo() @pytest.fixture(autouse=True) -def no_color(monkeypatch: MonkeyPatch, check_os_environ_stable: None) -> None: # noqa: ARG001, PT004 +def no_color(monkeypatch: pytest.MonkeyPatch, check_os_environ_stable: None) -> None: # noqa: ARG001, PT004 monkeypatch.setenv("NO_COLOR", "yes") @@ -138,11 +126,11 @@ def __init__( # noqa: PLR0913 base: Path | None, path: Path, capfd: CaptureFixture, - monkeypatch: MonkeyPatch, + monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture, ) -> None: self.path: Path = path - self.monkeypatch: MonkeyPatch = monkeypatch + self.monkeypatch: pytest.MonkeyPatch = monkeypatch self.mocker = mocker self._capfd = capfd self._setup_files(self.path, base, files) @@ -426,7 +414,7 @@ def __call__( def init_fixture( tmp_path: Path, capfd: CaptureFixture, - monkeypatch: MonkeyPatch, + monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture, ) -> ToxProjectCreator: def _init(files: dict[str, Any], base: Path | None = None, prj_path: Path | None = None) -> ToxProject: @@ -437,7 +425,7 @@ def _init(files: dict[str, Any], base: Path | None = None, prj_path: Path | None @pytest.fixture() -def empty_project(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch) -> ToxProject: +def empty_project(tox_project: ToxProjectCreator, monkeypatch: pytest.MonkeyPatch) -> ToxProject: project = tox_project({"tox.ini": ""}) monkeypatch.chdir(project.path) return project @@ -446,24 +434,24 @@ def empty_project(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch) -> T _RUN_INTEGRATION_TEST_FLAG = "--run-integration" -def pytest_addoption(parser: Parser) -> None: +def pytest_addoption(parser: pytest.Parser) -> None: parser.addoption(_RUN_INTEGRATION_TEST_FLAG, action="store_true", help="run the integration tests") -def pytest_configure(config: PyTestConfig) -> None: +def pytest_configure(config: pytest.Config) -> None: config.addinivalue_line("markers", "integration") config.addinivalue_line("markers", "plugin_test") @pytest.hookimpl(trylast=True) # type: ignore[misc] # not typed decorator -def pytest_collection_modifyitems(config: PyTestConfig, items: list[Function]) -> None: +def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Function]) -> None: # do not require flags if called directly if len(items) == 1: # pragma: no cover # hard to test return skip_int = pytest.mark.skip(reason=f"integration tests not run (no {_RUN_INTEGRATION_TEST_FLAG} flag)") - def is_integration(test_item: Function) -> bool: + def is_integration(test_item: pytest.Function) -> bool: return test_item.get_closest_marker("integration") is not None integration_enabled = config.getoption(_RUN_INTEGRATION_TEST_FLAG) @@ -475,7 +463,7 @@ def is_integration(test_item: Function) -> bool: items.sort(key=is_integration) -def enable_pypi_server(monkeypatch: MonkeyPatch, url: str | None) -> None: +def enable_pypi_server(monkeypatch: pytest.MonkeyPatch, url: str | None) -> None: if url is None: # pragma: no cover # only one of the branches can be hit depending on env monkeypatch.delenv("PIP_INDEX_URL", raising=False) else: # pragma: no cover @@ -485,7 +473,7 @@ def enable_pypi_server(monkeypatch: MonkeyPatch, url: str | None) -> None: @pytest.fixture(scope="session") -def pypi_server(tmp_path_factory: TempPathFactory) -> Iterator[IndexServer]: +def pypi_server(tmp_path_factory: pytest.TempPathFactory) -> Iterator[IndexServer]: # takes around 2.5s path = tmp_path_factory.mktemp("pypi") with IndexServer(path) as server: @@ -501,7 +489,7 @@ def _invalid_index_fake_port() -> int: # noqa: PT005 @pytest.fixture(autouse=True) -def disable_pip_pypi_access(_invalid_index_fake_port: int, monkeypatch: MonkeyPatch) -> tuple[str, str | None]: +def disable_pip_pypi_access(_invalid_index_fake_port: int, monkeypatch: pytest.MonkeyPatch) -> tuple[str, str | None]: """Set a fake pip index url, tests that want to use a pypi server should create and overwrite this.""" previous_url = os.environ.get("PIP_INDEX_URL") new_url = f"http://localhost:{_invalid_index_fake_port}/bad-pypi-server" @@ -514,7 +502,7 @@ def disable_pip_pypi_access(_invalid_index_fake_port: int, monkeypatch: MonkeyPa @pytest.fixture(name="enable_pip_pypi_access") def enable_pip_pypi_access_fixture( disable_pip_pypi_access: tuple[str, str | None], - monkeypatch: MonkeyPatch, + monkeypatch: pytest.MonkeyPatch, ) -> str | None: """Set a fake pip index url, tests that want to use a pypi server should create and overwrite this.""" _, previous_url = disable_pip_pypi_access @@ -532,6 +520,10 @@ def register_inline_plugin(mocker: MockerFixture, *args: Callable[..., Any]) -> mocker.patch("tox.plugin.manager.load_inline", return_value=plugin) +LogCaptureFixture = pytest.LogCaptureFixture +TempPathFactory = pytest.TempPathFactory +MonkeyPatch = pytest.MonkeyPatch + __all__ = ( "CaptureFixture", "LogCaptureFixture", diff --git a/src/tox/session/cmd/run/single.py b/src/tox/session/cmd/run/single.py index 5549256dc..c0dd78c55 100644 --- a/src/tox/session/cmd/run/single.py +++ b/src/tox/session/cmd/run/single.py @@ -50,12 +50,12 @@ def _evaluate(tox_env: RunToxEnv, no_test: bool) -> tuple[bool, int, list[Outcom code = 0 skipped = True except ToxBackendFailed as exception: - LOGGER.error("%s", exception) + LOGGER.error("%s", exception) # noqa: TRY400 raise SystemExit(exception.code) # noqa: B904, TRY200 except Fail as exception: - LOGGER.error("failed with %s", exception) + LOGGER.error("failed with %s", exception) # noqa: TRY400 code = 1 - except Exception: # pragma: no cover # noqa: BLE001 + except Exception: # pragma: no cover LOGGER.exception("internal error") # pragma: no cover code = 2 # pragma: no cover finally: diff --git a/src/tox/session/env_select.py b/src/tox/session/env_select.py index 359f61b9c..9b14a4ac4 100644 --- a/src/tox/session/env_select.py +++ b/src/tox/session/env_select.py @@ -5,7 +5,7 @@ from collections import Counter from dataclasses import dataclass from itertools import chain -from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, List, cast +from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, cast from tox.config.loader.str_convert import StrConvert from tox.config.types import EnvList @@ -46,10 +46,10 @@ def __str__(self) -> str: def __repr__(self) -> str: return f"{self.__class__.__name__}({'' if self.is_default_list else repr(str(self))})" - def __eq__(self, other: Any) -> bool: - return type(self) == type(other) and self._names == other._names + def __eq__(self, other: object) -> bool: + return type(self) == type(other) and self._names == other._names # type: ignore[attr-defined] - def __ne__(self, other: Any) -> bool: + def __ne__(self, other: object) -> bool: return not (self == other) @property diff --git a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py index ac0875a05..373b81b24 100644 --- a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py +++ b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py @@ -2,7 +2,6 @@ import glob import shutil -import sys import tarfile from functools import partial from io import TextIOWrapper @@ -34,10 +33,7 @@ from tox.tox_env.register import ToxEnvRegister from tox.tox_env.runner import RunToxEnv -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from importlib.metadata import Distribution -else: # pragma: no cover (py38+) - from importlib_metadata import Distribution +from importlib.metadata import Distribution class VirtualEnvCmdBuilder(PythonPackageToxEnv, VirtualEnv): diff --git a/src/tox/tox_env/python/virtual_env/package/pyproject.py b/src/tox/tox_env/python/virtual_env/package/pyproject.py index cffead997..050905f7c 100644 --- a/src/tox/tox_env/python/virtual_env/package/pyproject.py +++ b/src/tox/tox_env/python/virtual_env/package/pyproject.py @@ -38,10 +38,7 @@ from tox.tox_env.register import ToxEnvRegister from tox.tox_env.runner import RunToxEnv -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from importlib.metadata import Distribution, PathDistribution -else: # pragma: no cover (= (3, 11): # pragma: no cover (py311+) import tomllib diff --git a/tests/config/loader/ini/replace/conftest.py b/tests/config/loader/ini/replace/conftest.py index 6cb521108..208b9a136 100644 --- a/tests/config/loader/ini/replace/conftest.py +++ b/tests/config/loader/ini/replace/conftest.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from typing import TYPE_CHECKING import pytest @@ -13,10 +12,7 @@ if TYPE_CHECKING: from pathlib import Path -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Protocol -else: # pragma: no cover (= (3, 8): # pragma: no cover (py38+) - from typing import Literal -else: # pragma: no cover (py38+) - from typing_extensions import Literal +from typing import Literal @pytest.mark.parametrize( diff --git a/tests/config/test_set_env.py b/tests/config/test_set_env.py index 005c502c6..7effb6cd9 100644 --- a/tests/config/test_set_env.py +++ b/tests/config/test_set_env.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from pathlib import Path from typing import TYPE_CHECKING, Any from unittest.mock import ANY @@ -14,10 +13,7 @@ from tox.pytest import MonkeyPatch, ToxProjectCreator -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Protocol -else: # pragma: no cover ( None: diff --git a/tests/conftest.py b/tests/conftest.py index 1e3ed1b8d..f0c3d4833 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ import os import sys from pathlib import Path -from typing import TYPE_CHECKING, Callable, Iterator, Sequence +from typing import TYPE_CHECKING, Callable, Iterator, Protocol, Sequence from unittest.mock import patch from uuid import uuid4 @@ -19,8 +19,6 @@ from tox.tox_env.python.virtual_env.api import VirtualEnv if TYPE_CHECKING: - from _pytest.monkeypatch import MonkeyPatch - from _pytest.tmpdir import TempPathFactory from pytest_mock import MockerFixture from tox.config.loader.api import Override @@ -37,12 +35,6 @@ def _fmt(msg: str) -> str: return _fmt -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from typing import Protocol -else: # pragma: no cover ( Con @pytest.fixture() -def tox_ini_conf(tmp_path: Path, monkeypatch: MonkeyPatch) -> ToxIniCreator: +def tox_ini_conf(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> ToxIniCreator: def func(conf: str, override: Sequence[Override] | None = None) -> Config: dest = tmp_path / "c" dest.mkdir() @@ -117,7 +109,7 @@ def get_python(self: VirtualEnv, base_python: list[str]) -> PythonInfo | None: @pytest.fixture(scope="session", autouse=True) -def _do_not_share_virtualenv_for_parallel_runs(tmp_path_factory: TempPathFactory, worker_id: str) -> None: +def _do_not_share_virtualenv_for_parallel_runs(tmp_path_factory: pytest.TempPathFactory, worker_id: str) -> None: # virtualenv uses locks to manage access to its cache, when running with xdist this may throw off test timings if worker_id != "master": # pragma: no branch temp_app_data = str(tmp_path_factory.mktemp(f"virtualenv-app-{worker_id}")) # pragma: no cover @@ -128,7 +120,7 @@ def _do_not_share_virtualenv_for_parallel_runs(tmp_path_factory: TempPathFactory @pytest.fixture(scope="session") -def fake_exe_on_path(tmp_path_factory: TempPathFactory) -> Iterator[Path]: +def fake_exe_on_path(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Path]: tmp_path = Path(tmp_path_factory.mktemp("a")) cmd_name = uuid4().hex maker = ScriptMaker(None, str(tmp_path)) @@ -140,7 +132,7 @@ def fake_exe_on_path(tmp_path_factory: TempPathFactory) -> Iterator[Path]: @pytest.fixture(scope="session") -def demo_pkg_inline_wheel(tmp_path_factory: TempPathFactory, demo_pkg_inline: Path) -> Path: +def demo_pkg_inline_wheel(tmp_path_factory: pytest.TempPathFactory, demo_pkg_inline: Path) -> Path: return build_pkg(tmp_path_factory.mktemp("dist"), demo_pkg_inline, ["wheel"]) diff --git a/tests/demo_pkg_inline/build.py b/tests/demo_pkg_inline/build.py index a56db5b80..1ae8ece8d 100644 --- a/tests/demo_pkg_inline/build.py +++ b/tests/demo_pkg_inline/build.py @@ -70,16 +70,13 @@ def tox_register_tox_env(register: ToxEnvRegister) -> None: Tag: py{sys.version_info[0]}-none-any """, f"{dist_info}/top_level.txt": name, - record: """ - {0}/__init__.py,, - {1}/METADATA,, - {1}/WHEEL,, - {1}/top_level.txt,, - {1}/RECORD,, - """.format( - name, - dist_info, - ), + record: f""" + {name}/__init__.py,, + {dist_info}/METADATA,, + {dist_info}/WHEEL,, + {dist_info}/top_level.txt,, + {dist_info}/RECORD,, + """, } diff --git a/tests/execute/local_subprocess/test_local_subprocess.py b/tests/execute/local_subprocess/test_local_subprocess.py index 966cfea7d..22c854d73 100644 --- a/tests/execute/local_subprocess/test_local_subprocess.py +++ b/tests/execute/local_subprocess/test_local_subprocess.py @@ -115,12 +115,12 @@ def test_local_execute_write_a_lot(os_env: dict[str, str]) -> None: "-c", ( "import sys; import time; from datetime import datetime; import os;" - "print('e' * {0}, file=sys.stderr);" - "print('o' * {0}, file=sys.stdout);" + f"print('e' * {count}, file=sys.stderr);" + f"print('o' * {count}, file=sys.stdout);" "time.sleep(0.5);" - "print('a' * {0}, file=sys.stderr);" - "print('b' * {0}, file=sys.stdout);" - ).format(count), + f"print('a' * {count}, file=sys.stderr);" + f"print('b' * {count}, file=sys.stdout);" + ), ], cwd=Path(), env=os_env, diff --git a/tests/test_provision.py b/tests/test_provision.py index c640fe975..f9275fb5e 100644 --- a/tests/test_provision.py +++ b/tests/test_provision.py @@ -20,10 +20,7 @@ from tox.pytest import MonkeyPatch, TempPathFactory, ToxProjectCreator -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from importlib.metadata import Distribution -else: # pragma: no cover ( Path: +def pkg_with_extras_project(tmp_path_factory: pytest.TempPathFactory) -> Path: py_ver = ".".join(str(i) for i in sys.version_info[0:2]) setup_cfg = f""" [metadata] diff --git a/tests/tox_env/python/virtual_env/package/test_python_package_util.py b/tests/tox_env/python/virtual_env/package/test_python_package_util.py index 394f0b9e0..498583ba4 100644 --- a/tests/tox_env/python/virtual_env/package/test_python_package_util.py +++ b/tests/tox_env/python/virtual_env/package/test_python_package_util.py @@ -13,10 +13,7 @@ if TYPE_CHECKING: from pathlib import Path -if sys.version_info >= (3, 8): # pragma: no cover (py38+) - from importlib.metadata import Distribution, PathDistribution -else: # pragma: no cover (=5.3.0.5 + mypy==1.5 + types-cachetools>=5.3.0.6 types-chardet>=5.0.4.6 commands = mypy src/tox