Skip to content

Commit

Permalink
Merge TypedDict from typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Nov 1, 2024
1 parent f410da1 commit 0353c55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 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
4 changes: 3 additions & 1 deletion setuptools/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def _called_from_setup(run_frame):
return False

def do_egg_install(self) -> None:
easy_install = self.distribution.get_command_class('easy_install')
easy_install = cast(
type[easy_install_cls], self.distribution.get_command_class('easy_install')
)

cmd = cast(
# We'd want to cast easy_install as type[easy_install_cls] but a bug in
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 0353c55

Please sign in to comment.