From eca1d66335211afbafcfbd92878402432efdf174 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 1 Nov 2024 14:17:06 -0400 Subject: [PATCH] Merge TypedDict from typeshed --- setuptools/command/easy_install.py | 11 ++++++++--- setuptools/msvc.py | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 7ecb071f06..e1cd32cf0d 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -34,7 +34,7 @@ from collections.abc import Iterable from glob import glob from sysconfig import get_path -from typing import TYPE_CHECKING, Callable, NoReturn, TypeVar +from typing import TYPE_CHECKING, Callable, NoReturn, TypedDict, TypeVar from jaraco.text import yield_lines @@ -2039,6 +2039,11 @@ def chmod(path, mode): log.debug("chmod failed: %s", e) +class _SplitArgs(TypedDict, total=False): + comments: bool + posix: bool + + class CommandSpec(list): """ A command spec for a #! header, specified as a list of arguments akin to @@ -2046,7 +2051,7 @@ class CommandSpec(list): """ options: list[str] = [] - split_args: dict[str, bool] = dict() + split_args = _SplitArgs() @classmethod def best(cls): @@ -2129,7 +2134,7 @@ def _render(items): class WindowsCommandSpec(CommandSpec): - split_args = dict(posix=False) + split_args = _SplitArgs(posix=False) class ScriptWriter: diff --git a/setuptools/msvc.py b/setuptools/msvc.py index ad4a2f375f..55f5090878 100644 --- a/setuptools/msvc.py +++ b/setuptools/msvc.py @@ -13,12 +13,15 @@ import os import os.path import platform -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TypedDict from more_itertools import unique_everseen import distutils.errors +if TYPE_CHECKING: + from typing_extensions import NotRequired + # https://github.com/python/mypy/issues/8166 if not TYPE_CHECKING and platform.system() == 'Windows': import winreg @@ -876,6 +879,14 @@ def _use_last_dir_name(path, prefix=''): return next(matching_dirs, None) or '' +class _EnvironmentDict(TypedDict): + include: str + lib: str + libpath: str + path: str + py_vcruntime_redist: NotRequired[str | None] + + class EnvironmentInfo: """ Return environment variables for specified Microsoft Visual C++ version @@ -1420,7 +1431,7 @@ def VCRuntimeRedist(self) -> str | None: ) return next(filter(os.path.isfile, candidate_paths), None) # type: ignore[arg-type] #python/mypy#12682 - def return_env(self, exists=True): + def return_env(self, exists: bool = True) -> _EnvironmentDict: """ Return environment dict. @@ -1434,7 +1445,7 @@ def return_env(self, exists=True): dict environment """ - env = dict( + env = _EnvironmentDict( include=self._build_paths( 'include', [