From 70d335bdf02c8d8d909a55951d6844c6258f408f Mon Sep 17 00:00:00 2001 From: finswimmer Date: Tue, 17 Sep 2024 06:16:12 +0200 Subject: [PATCH] feat: drop support for Python 3.8 --- .github/workflows/tests.yaml | 2 +- poetry.lock | 35 ++----------------- pyproject.toml | 4 +-- src/poetry/console/commands/env/remove.py | 5 ++- src/poetry/console/commands/init.py | 5 ++- src/poetry/inspection/info.py | 6 ++-- src/poetry/mixology/version_solver.py | 3 +- src/poetry/packages/direct_origin.py | 2 +- src/poetry/packages/package_collection.py | 3 +- src/poetry/puzzle/solver.py | 4 +-- src/poetry/repositories/http_repository.py | 3 +- src/poetry/repositories/link_sources/base.py | 5 ++- src/poetry/utils/_compat.py | 22 ------------ src/poetry/utils/dependency_specification.py | 4 +-- src/poetry/utils/env/base_env.py | 4 +-- src/poetry/utils/isolated_build.py | 4 +-- tests/conftest.py | 2 +- tests/console/commands/test_check.py | 2 +- tests/helpers.py | 2 +- tests/inspection/test_info.py | 2 +- tests/integration/test_utils_vcs_git.py | 3 +- .../masonry/builders/test_editable_builder.py | 3 +- tests/packages/test_locker.py | 12 ++++--- .../fixtures/pypi.org/generate.py | 26 +++++++++----- tests/repositories/fixtures/python_hosted.py | 2 +- .../repositories/test_installed_repository.py | 3 +- tests/types.py | 10 +++--- tests/utils/env/test_env.py | 2 +- 28 files changed, 64 insertions(+), 116 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 72aecab2a4b..51ad38e5f91 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -123,7 +123,7 @@ jobs: image: windows-2022 - name: macOS aarch64 image: macos-14 - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12"] fail-fast: false status: diff --git a/poetry.lock b/poetry.lock index 91fc217135f..3a03dc3a442 100644 --- a/poetry.lock +++ b/poetry.lock @@ -606,24 +606,6 @@ doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linke perf = ["ipython"] test = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "packaging", "pyfakefs", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-perf (>=0.9.2)", "pytest-ruff (>=0.2.1)"] -[[package]] -name = "importlib-resources" -version = "6.4.0" -description = "Read resources from Python packages" -optional = false -python-versions = ">=3.8" -files = [ - {file = "importlib_resources-6.4.0-py3-none-any.whl", hash = "sha256:50d10f043df931902d4194ea07ec57960f66a80449ff867bfe782b4c486ba78c"}, - {file = "importlib_resources-6.4.0.tar.gz", hash = "sha256:cdb2b453b8046ca4e3798eb1d84f3cce1446a0e8e7b5ef4efb600f19fc398145"}, -] - -[package.dependencies] -zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["jaraco.test (>=5.4)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-ruff (>=0.2.1)", "zipp (>=3.17)"] - [[package]] name = "iniconfig" version = "2.0.0" @@ -728,7 +710,6 @@ files = [ [package.dependencies] importlib-metadata = {version = ">=4.11.4", markers = "python_version < \"3.12\""} -importlib-resources = {version = "*", markers = "python_version < \"3.9\""} "jaraco.classes" = "*" "jaraco.context" = "*" "jaraco.functools" = "*" @@ -814,7 +795,6 @@ files = [ {file = "msgpack-1.0.8-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5fbb160554e319f7b22ecf530a80a3ff496d38e8e07ae763b9e82fadfe96f273"}, {file = "msgpack-1.0.8-cp39-cp39-win32.whl", hash = "sha256:f9af38a89b6a5c04b7d18c492c8ccf2aee7048aff1ce8437c4683bb5a1df893d"}, {file = "msgpack-1.0.8-cp39-cp39-win_amd64.whl", hash = "sha256:ed59dd52075f8fc91da6053b12e8c89e37aa043f8986efd89e61fae69dc1b011"}, - {file = "msgpack-1.0.8-py3-none-any.whl", hash = "sha256:24f727df1e20b9876fa6e95f840a2a2651e34c0ad147676356f4bf5fbb0206ca"}, {file = "msgpack-1.0.8.tar.gz", hash = "sha256:95c02b0e27e706e48d0e5426d1710ca78e0f0628d6e89d5b5a5b91a5f12274f3"}, ] @@ -1211,7 +1191,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -1219,16 +1198,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -1245,7 +1216,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -1253,7 +1223,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -1626,5 +1595,5 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" -python-versions = "^3.8" -content-hash = "816bcb3532fd7484005946146373ddb848e7405a72f10a8dc345b9e4596427f7" +python-versions = "^3.9" +content-hash = "2d9e3f4c638fa36577155f2979a2efd3c4c07b1381eda7dfdff90f1f45746a41" diff --git a/pyproject.toml b/pyproject.toml index f9fe2d313e3..2b12d4b56ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ Changelog = "https://python-poetry.org/history/" # Requirements [tool.poetry.dependencies] -python = "^3.8" +python = "^3.9" poetry-core = { git = "https://github.com/python-poetry/poetry-core.git", branch = "main" } poetry-plugin-export = "^1.8.0" @@ -105,7 +105,7 @@ extend-exclude = [ ] fix = true line-length = 88 -target-version = "py38" +target-version = "py39" [tool.ruff.lint] extend-select = [ diff --git a/src/poetry/console/commands/env/remove.py b/src/poetry/console/commands/env/remove.py index f19e9aa505f..a492959ebbe 100644 --- a/src/poetry/console/commands/env/remove.py +++ b/src/poetry/console/commands/env/remove.py @@ -7,7 +7,6 @@ from cleo.helpers import option from poetry.console.commands.command import Command -from poetry.utils._compat import is_relative_to if TYPE_CHECKING: @@ -55,8 +54,8 @@ def handle(self) -> int: self.line(f"Deleted virtualenv: {venv.path}") if remove_all_envs or is_in_project: for venv in manager.list(): - if not is_in_project or is_relative_to( - venv.path, self.poetry.pyproject_path.parent + if not is_in_project or venv.path.is_relative_to( + self.poetry.pyproject_path.parent ): manager.remove_venv(venv.path) self.line(f"Deleted virtualenv: {venv.path}") diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index 595b53fc232..d01b9a36249 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -1,12 +1,11 @@ from __future__ import annotations +from collections.abc import Mapping from contextlib import suppress from pathlib import Path from typing import TYPE_CHECKING from typing import Any from typing import ClassVar -from typing import Dict -from typing import Mapping from typing import Union from cleo.helpers import option @@ -26,7 +25,7 @@ from poetry.repositories import RepositoryPool -Requirements = Dict[str, Union[str, Mapping[str, Any]]] +Requirements = dict[str, Union[str, Mapping[str, Any]]] class InitCommand(Command): diff --git a/src/poetry/inspection/info.py b/src/poetry/inspection/info.py index 457fc97555f..597223ba983 100644 --- a/src/poetry/inspection/info.py +++ b/src/poetry/inspection/info.py @@ -9,8 +9,6 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any -from typing import Mapping -from typing import Sequence import pkginfo @@ -31,6 +29,8 @@ if TYPE_CHECKING: from collections.abc import Iterator + from collections.abc import Mapping + from collections.abc import Sequence from packaging.metadata import RawMetadata from packaging.utils import NormalizedName @@ -523,7 +523,7 @@ def from_path(cls, path: Path) -> PackageInfo: return cls.from_sdist(path=path) -@functools.lru_cache(maxsize=None) +@functools.cache def get_pep517_metadata(path: Path) -> PackageInfo: """ Helper method to use PEP-517 library to build and read package metadata. diff --git a/src/poetry/mixology/version_solver.py b/src/poetry/mixology/version_solver.py index 5bb02d9418a..46d7b36cad0 100644 --- a/src/poetry/mixology/version_solver.py +++ b/src/poetry/mixology/version_solver.py @@ -6,7 +6,6 @@ from typing import TYPE_CHECKING from typing import Optional -from typing import Tuple from poetry.core.packages.dependency import Dependency @@ -32,7 +31,7 @@ _conflict = object() -DependencyCacheKey = Tuple[ +DependencyCacheKey = tuple[ str, Optional[str], Optional[str], Optional[str], Optional[str] ] diff --git a/src/poetry/packages/direct_origin.py b/src/poetry/packages/direct_origin.py index 561b7a4223e..af98ac2e4e1 100644 --- a/src/poetry/packages/direct_origin.py +++ b/src/poetry/packages/direct_origin.py @@ -22,7 +22,7 @@ from poetry.utils.cache import ArtifactCache -@functools.lru_cache(maxsize=None) +@functools.cache def _get_package_from_git( url: str, branch: str | None = None, diff --git a/src/poetry/packages/package_collection.py b/src/poetry/packages/package_collection.py index e08d9a31846..4457b506169 100644 --- a/src/poetry/packages/package_collection.py +++ b/src/poetry/packages/package_collection.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import TYPE_CHECKING -from typing import List from poetry.packages.dependency_package import DependencyPackage @@ -13,7 +12,7 @@ from poetry.core.packages.package import Package -class PackageCollection(List[DependencyPackage]): +class PackageCollection(list[DependencyPackage]): def __init__( self, dependency: Dependency, diff --git a/src/poetry/puzzle/solver.py b/src/poetry/puzzle/solver.py index 16432b3e297..f76985ffbe9 100644 --- a/src/poetry/puzzle/solver.py +++ b/src/poetry/puzzle/solver.py @@ -5,8 +5,6 @@ from collections import defaultdict from contextlib import contextmanager from typing import TYPE_CHECKING -from typing import FrozenSet -from typing import Tuple from poetry.mixology import resolve_version from poetry.mixology.failure import SolveFailure @@ -197,7 +195,7 @@ def _solve(self) -> tuple[list[Package], list[int]]: return final_packages, depths -DFSNodeID = Tuple[str, FrozenSet[str], bool] +DFSNodeID = tuple[str, frozenset[str], bool] class DFSNode: diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index 7d0249b897d..37662155dce 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -8,7 +8,6 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any -from typing import Iterator import requests import requests.adapters @@ -36,6 +35,8 @@ if TYPE_CHECKING: + from collections.abc import Iterator + from packaging.utils import NormalizedName from poetry.core.packages.utils.link import Link diff --git a/src/poetry/repositories/link_sources/base.py b/src/poetry/repositories/link_sources/base.py index 9948ec8cd35..35de660bb89 100644 --- a/src/poetry/repositories/link_sources/base.py +++ b/src/poetry/repositories/link_sources/base.py @@ -6,8 +6,6 @@ from functools import cached_property from typing import TYPE_CHECKING from typing import ClassVar -from typing import DefaultDict -from typing import List from poetry.core.constraints.version import Version from poetry.core.packages.package import Package @@ -18,12 +16,13 @@ if TYPE_CHECKING: + from collections import defaultdict from collections.abc import Iterator from packaging.utils import NormalizedName from poetry.core.packages.utils.link import Link - LinkCache = DefaultDict[NormalizedName, DefaultDict[Version, List[Link]]] + LinkCache = defaultdict[NormalizedName, defaultdict[Version, list[Link]]] logger = logging.getLogger(__name__) diff --git a/src/poetry/utils/_compat.py b/src/poetry/utils/_compat.py index 6781096ddaf..4b2a74eab19 100644 --- a/src/poetry/utils/_compat.py +++ b/src/poetry/utils/_compat.py @@ -4,11 +4,6 @@ import sys from contextlib import suppress -from typing import TYPE_CHECKING - - -if TYPE_CHECKING: - from pathlib import Path if sys.version_info < (3, 11): @@ -60,28 +55,11 @@ def getencoding() -> str: return locale.getencoding() -def is_relative_to(this: Path, other: Path) -> bool: - """ - Return whether `this` path is relative to the `other` path. This is compatibility wrapper around - `PurePath.is_relative_to()` method. This method was introduced only in Python 3.9. - - See: https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.is_relative_to - """ - if sys.version_info < (3, 9): - with suppress(ValueError): - this.relative_to(other) - return True - return False - - return this.is_relative_to(other) - - __all__ = [ "WINDOWS", "decode", "encode", "getencoding", - "is_relative_to", "metadata", "tomllib", ] diff --git a/src/poetry/utils/dependency_specification.py b/src/poetry/utils/dependency_specification.py index fc21fe5cf46..4071fbcd7b7 100644 --- a/src/poetry/utils/dependency_specification.py +++ b/src/poetry/utils/dependency_specification.py @@ -7,8 +7,6 @@ from pathlib import Path from typing import TYPE_CHECKING -from typing import Dict -from typing import List from typing import TypeVar from typing import Union from typing import cast @@ -26,7 +24,7 @@ from poetry.utils.env import Env -DependencySpec = Dict[str, Union[str, bool, Dict[str, Union[str, bool]], List[str]]] +DependencySpec = dict[str, Union[str, bool, dict[str, Union[str, bool]], list[str]]] BaseSpec = TypeVar("BaseSpec", DependencySpec, InlineTable) GIT_URL_SCHEMES = {"git+http", "git+https", "git+ssh"} diff --git a/src/poetry/utils/env/base_env.py b/src/poetry/utils/env/base_env.py index 5a8f2fc6146..5aedb3d4f39 100644 --- a/src/poetry/utils/env/base_env.py +++ b/src/poetry/utils/env/base_env.py @@ -21,15 +21,13 @@ if TYPE_CHECKING: - from typing import Tuple - from packaging.tags import Tag from poetry.core.version.markers import BaseMarker from virtualenv.seed.wheels.util import Wheel from poetry.utils.env.generic_env import GenericEnv - PythonVersion = Tuple[int, int, int, str, int] + PythonVersion = tuple[int, int, int, str, int] class Env: diff --git a/src/poetry/utils/isolated_build.py b/src/poetry/utils/isolated_build.py index 5879676c691..abbd468f991 100644 --- a/src/poetry/utils/isolated_build.py +++ b/src/poetry/utils/isolated_build.py @@ -6,8 +6,6 @@ from contextlib import redirect_stdout from io import StringIO from typing import TYPE_CHECKING -from typing import Collection -from typing import Iterator from build.env import IsolatedEnv as BaseIsolatedEnv @@ -17,6 +15,8 @@ if TYPE_CHECKING: + from collections.abc import Collection + from collections.abc import Iterator from pathlib import Path from build import DistributionType diff --git a/tests/conftest.py b/tests/conftest.py index 53641dcb1d7..905d530c109 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,10 +7,10 @@ import shutil import sys +from collections.abc import Iterator from pathlib import Path from typing import TYPE_CHECKING from typing import Any -from typing import Iterator import httpretty import keyring diff --git a/tests/console/commands/test_check.py b/tests/console/commands/test_check.py index 1496ebcd544..5d0b0226d8d 100644 --- a/tests/console/commands/test_check.py +++ b/tests/console/commands/test_check.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: - from typing import Iterator + from collections.abc import Iterator from cleo.testers.command_tester import CommandTester from pytest_mock import MockerFixture diff --git a/tests/helpers.py b/tests/helpers.py index 431b52c5df9..bb3871813ed 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -24,8 +24,8 @@ if TYPE_CHECKING: from collections.abc import Iterator + from collections.abc import Mapping from typing import Any - from typing import Mapping import httpretty diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index d0e4ac14dec..62c1f77732a 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -4,7 +4,6 @@ from subprocess import CalledProcessError from typing import TYPE_CHECKING -from typing import Iterator from zipfile import ZipFile import pytest @@ -20,6 +19,7 @@ if TYPE_CHECKING: + from collections.abc import Iterator from pathlib import Path from packaging.metadata import RawMetadata diff --git a/tests/integration/test_utils_vcs_git.py b/tests/integration/test_utils_vcs_git.py index 069566a22c5..8e8aeee56c6 100644 --- a/tests/integration/test_utils_vcs_git.py +++ b/tests/integration/test_utils_vcs_git.py @@ -7,7 +7,6 @@ from hashlib import sha1 from pathlib import Path from typing import TYPE_CHECKING -from typing import Iterator from typing import TypedDict from urllib.parse import urlparse from urllib.parse import urlunparse @@ -27,6 +26,8 @@ if TYPE_CHECKING: + from collections.abc import Iterator + from _pytest.tmpdir import TempPathFactory from dulwich.client import FetchPackResult from dulwich.client import GitClient diff --git a/tests/masonry/builders/test_editable_builder.py b/tests/masonry/builders/test_editable_builder.py index 82c63426b90..b7e7c116cde 100644 --- a/tests/masonry/builders/test_editable_builder.py +++ b/tests/masonry/builders/test_editable_builder.py @@ -7,7 +7,6 @@ from pathlib import Path from typing import TYPE_CHECKING -from typing import Iterator import pytest @@ -29,6 +28,8 @@ if TYPE_CHECKING: + from collections.abc import Iterator + from pytest_mock import MockerFixture from poetry.poetry import Poetry diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index 0c3203b0b1d..0d449a89d1e 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -1140,11 +1140,13 @@ def test_lock_file_resolves_file_url_symlinks(root: ProjectPackage) -> None: """ with tempfile.TemporaryDirectory() as d1: symlink_path = Path(d1).joinpath("testsymlink") - with tempfile.TemporaryDirectory(dir=d1) as d2, tempfile.TemporaryDirectory( - dir=d1 - ) as d4, tempfile.TemporaryDirectory(dir=d2) as d3, tempfile.NamedTemporaryFile( - dir=d4 - ) as source_file, tempfile.NamedTemporaryFile(dir=d3) as lock_file: + with ( + tempfile.TemporaryDirectory(dir=d1) as d2, + tempfile.TemporaryDirectory(dir=d1) as d4, + tempfile.TemporaryDirectory(dir=d2) as d3, + tempfile.NamedTemporaryFile(dir=d4) as source_file, + tempfile.NamedTemporaryFile(dir=d3) as lock_file, + ): lock_file.close() try: os.symlink(Path(d3), symlink_path) diff --git a/tests/repositories/fixtures/pypi.org/generate.py b/tests/repositories/fixtures/pypi.org/generate.py index ccc535dcc55..e452d894df8 100644 --- a/tests/repositories/fixtures/pypi.org/generate.py +++ b/tests/repositories/fixtures/pypi.org/generate.py @@ -48,7 +48,6 @@ from typing import TYPE_CHECKING from typing import Any from typing import Callable -from typing import Iterator from packaging.metadata import parse_email from poetry.core.masonry.builders.sdist import SdistBuilder @@ -64,6 +63,8 @@ if TYPE_CHECKING: + from collections.abc import Iterator + import requests from poetry.core.packages.utils.link import Link @@ -325,9 +326,13 @@ def process_zipfile(self, link: Link) -> ReleaseFileMetadata: dst.relative_to(FIXTURE_PATH_REPOSITORIES_PYPI), ) - with self.pypi._cached_or_downloaded_file(link) as src, zipfile.ZipFile( - dst, "w", compression=zipfile.ZIP_DEFLATED - ) as stubbed_sdist, zipfile.ZipFile(src) as zf: + with ( + self.pypi._cached_or_downloaded_file(link) as src, + zipfile.ZipFile( + dst, "w", compression=zipfile.ZIP_DEFLATED + ) as stubbed_sdist, + zipfile.ZipFile(src) as zf, + ): for member in zf.infolist(): if not is_protected(member.filename): logger.debug("Stubbing file %s(%s)", link.filename, member.filename) @@ -350,11 +355,14 @@ def process_tarfile(self, link: Link) -> ReleaseFileMetadata: dst.relative_to(FIXTURE_PATH_REPOSITORIES_PYPI), ) - with self.pypi._cached_or_downloaded_file(link) as src, GzipFile( - dst.as_posix(), mode="wb", mtime=0 - ) as gz, tarfile.TarFile( - dst, mode="w", fileobj=gz, format=tarfile.PAX_FORMAT - ) as dst_tf, tarfile.open(src, "r") as src_tf: + with ( + self.pypi._cached_or_downloaded_file(link) as src, + GzipFile(dst.as_posix(), mode="wb", mtime=0) as gz, + tarfile.TarFile( + dst, mode="w", fileobj=gz, format=tarfile.PAX_FORMAT + ) as dst_tf, + tarfile.open(src, "r") as src_tf, + ): for member in src_tf.getmembers(): member.mtime = 0 member = SdistBuilder.clean_tarinfo(member) diff --git a/tests/repositories/fixtures/python_hosted.py b/tests/repositories/fixtures/python_hosted.py index a00f494e916..fcda8724408 100644 --- a/tests/repositories/fixtures/python_hosted.py +++ b/tests/repositories/fixtures/python_hosted.py @@ -2,10 +2,10 @@ import re +from collections.abc import Iterator from pathlib import Path from typing import TYPE_CHECKING from typing import Any -from typing import Iterator from urllib.parse import urlparse import pytest diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index 0645f0256bf..630ccf26aae 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -6,7 +6,6 @@ from pathlib import Path from typing import TYPE_CHECKING -from typing import Iterator from typing import NamedTuple import pytest @@ -21,6 +20,8 @@ if TYPE_CHECKING: + from collections.abc import Iterator + from _pytest.logging import LogCaptureFixture from poetry.core.packages.package import Package from pytest_mock.plugin import MockerFixture diff --git a/tests/types.py b/tests/types.py index 840545bf27f..a9b2e8079d9 100644 --- a/tests/types.py +++ b/tests/types.py @@ -7,10 +7,8 @@ if TYPE_CHECKING: from collections.abc import Callable + from contextlib import AbstractContextManager from pathlib import Path - from typing import ContextManager - from typing import Dict - from typing import Tuple from cleo.io.io import IO from cleo.testers.command_tester import CommandTester @@ -26,9 +24,9 @@ from poetry.utils.env import Env from tests.repositories.fixtures.distribution_hashes import DistributionHash - HTTPrettyResponse = Tuple[int, Dict[str, Any], bytes] # status code, headers, body + HTTPrettyResponse = tuple[int, dict[str, Any], bytes] # status code, headers, body HTTPrettyRequestCallback = Callable[ - [HTTPrettyRequest, str, Dict[str, Any]], HTTPrettyResponse + [HTTPrettyRequest, str, dict[str, Any]], HTTPrettyResponse ] HTTPPrettyRequestCallbackWrapper = Callable[ [HTTPrettyRequestCallback], HTTPrettyRequestCallback @@ -111,4 +109,4 @@ def __call__(self, name: str) -> DistributionHash: ... class SetProjectContext(Protocol): def __call__( self, project: str | Path, in_place: bool = False - ) -> ContextManager[Path]: ... + ) -> AbstractContextManager[Path]: ... diff --git a/tests/utils/env/test_env.py b/tests/utils/env/test_env.py index 745b33a091d..01c73d54052 100644 --- a/tests/utils/env/test_env.py +++ b/tests/utils/env/test_env.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: - from typing import Iterator + from collections.abc import Iterator from pytest_mock import MockerFixture