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 39179c1 commit 1e602fb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 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
12 changes: 10 additions & 2 deletions setuptools/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import inspect
import platform
from collections.abc import Callable
from typing import Any, ClassVar, cast
from typing import TYPE_CHECKING, Any, ClassVar, cast

import setuptools

Expand All @@ -15,6 +15,12 @@
import distutils.command.install as orig
from distutils.errors import DistutilsArgError

if TYPE_CHECKING:
# This is only used for a type-cast, don't import at runtime or it'll cause deprecation warnings
from .easy_install import easy_install as easy_install_cls
else:
easy_install_cls = type()

# Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for
# now. See https://github.com/pypa/setuptools/issues/199/
_install = orig.install
Expand Down Expand Up @@ -131,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 = easy_install(
self.distribution,
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 1e602fb

Please sign in to comment.