Skip to content

Merge TypedDicts from typeshed #4707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading