From c47aad19d42793ccc7bb466790936230f115c635 Mon Sep 17 00:00:00 2001 From: dylan-robins Date: Sun, 31 Mar 2024 13:42:46 +0200 Subject: [PATCH] Removed dependency on typing_extensions & hid uses behind `if TYPE_CHECKING` guards --- poetry.lock | 2 +- pyproject.toml | 1 - src/poetry/core/factory.py | 18 ++++++---- src/poetry/core/packages/project_package.py | 37 +++++++++------------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/poetry.lock b/poetry.lock index 37b79b51c..170c2d4f4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1042,4 +1042,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "7b6c3cce0a3510ee989278d1f866ca0eb3f95c49a6eb2017ec3ba223a482f724" +content-hash = "f735bca440c1c1eeba822e475315a9c86fcb2cbb4f9aa3cd6920527cb9a5a55d" diff --git a/pyproject.toml b/pyproject.toml index 6bf6fd534..02b0735ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ include = [ [tool.poetry.dependencies] python = "^3.8" -typing-extensions = "^4.10.0" [tool.poetry.group.dev.dependencies] pre-commit = ">=2.15.0" diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index e87987a7b..0748249a4 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -8,21 +8,22 @@ from typing import Any from typing import List from typing import Union -from typing import cast from packaging.utils import canonicalize_name -from poetry.core.packages.project_package import BuildConfigSpec -from poetry.core.packages.project_package import IncludeSpec from poetry.core.utils.helpers import combine_unicode from poetry.core.utils.helpers import readme_content_type if TYPE_CHECKING: + from typing import cast + from packaging.utils import NormalizedName from poetry.core.packages.dependency import Dependency from poetry.core.packages.dependency_group import DependencyGroup + from poetry.core.packages.project_package import BuildConfigSpec + from poetry.core.packages.project_package import IncludeSpec from poetry.core.packages.project_package import ProjectPackage from poetry.core.poetry import Poetry from poetry.core.spdx.license import License @@ -200,9 +201,13 @@ def configure_package( if "build" in config: build = config["build"] + if not build: + build = {} if not isinstance(build, dict): build = {"script": build} - package.build_config = cast(BuildConfigSpec, build) or {} + if TYPE_CHECKING: + cast(BuildConfigSpec, build) + package.build_config = build if "include" in config: package.include = [] @@ -215,8 +220,9 @@ def configure_package( if formats and not isinstance(formats, list): formats = [formats] include["format"] = formats - - package.include.append(cast(IncludeSpec, include)) + if TYPE_CHECKING: + include = cast(IncludeSpec, include) + package.include.append(include) if "exclude" in config: package.exclude = config["exclude"] diff --git a/src/poetry/core/packages/project_package.py b/src/poetry/core/packages/project_package.py index de749d122..e20041c24 100644 --- a/src/poetry/core/packages/project_package.py +++ b/src/poetry/core/packages/project_package.py @@ -8,38 +8,33 @@ from typing import Sequence from typing import TypedDict -from typing_extensions import NotRequired - from poetry.core.constraints.version import parse_constraint +from poetry.core.packages.package import Package +from poetry.core.packages.utils.utils import create_nested_marker from poetry.core.version.markers import parse_marker if TYPE_CHECKING: + from typing_extensions import NotRequired + from poetry.core.constraints.version import Version from poetry.core.packages.dependency import Dependency -from poetry.core.packages.package import Package -from poetry.core.packages.utils.utils import create_nested_marker - - -SupportedPackageFormats = Literal["sdist", "wheel"] - - -BuildConfigSpec = TypedDict( - "BuildConfigSpec", - {"script": NotRequired[str], "generate-setup-file": NotRequired[bool]}, -) - + SupportedPackageFormats = Literal["sdist", "wheel"] -class PackageSpec(TypedDict): - include: str - to: str - format: list[SupportedPackageFormats] + BuildConfigSpec = TypedDict( + "BuildConfigSpec", + {"script": NotRequired[str], "generate-setup-file": NotRequired[bool]}, + ) + class PackageSpec(TypedDict): + include: str + to: str + format: list[SupportedPackageFormats] -class IncludeSpec(TypedDict): - path: str - format: list[SupportedPackageFormats] + class IncludeSpec(TypedDict): + path: str + format: list[SupportedPackageFormats] class ProjectPackage(Package):