Skip to content

Commit

Permalink
Merge TypedDicts from typeshed (#4707)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri authored Nov 4, 2024
2 parents bf582cb + eca1d66 commit 12aadb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 8 additions & 3 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -2039,14 +2039,19 @@ 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
those passed to Popen.
"""

options: list[str] = []
split_args: dict[str, bool] = dict()
split_args = _SplitArgs()

@classmethod
def best(cls):
Expand Down Expand Up @@ -2129,7 +2134,7 @@ def _render(items):


class WindowsCommandSpec(CommandSpec):
split_args = dict(posix=False)
split_args = _SplitArgs(posix=False)


class ScriptWriter:
Expand Down
17 changes: 14 additions & 3 deletions setuptools/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -1434,7 +1445,7 @@ def return_env(self, exists=True):
dict
environment
"""
env = dict(
env = _EnvironmentDict(
include=self._build_paths(
'include',
[
Expand Down

0 comments on commit 12aadb1

Please sign in to comment.