Skip to content

Commit 2aece55

Browse files
committed
Merge TypedDict from typeshed
1 parent a9a79e7 commit 2aece55

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

setuptools/command/easy_install.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from collections.abc import Iterable
3535
from glob import glob
3636
from sysconfig import get_path
37-
from typing import TYPE_CHECKING, Callable, TypeVar
37+
from typing import TYPE_CHECKING, Callable, TypedDict, TypeVar
3838

3939
from jaraco.text import yield_lines
4040

@@ -2038,14 +2038,19 @@ def chmod(path, mode):
20382038
log.debug("chmod failed: %s", e)
20392039

20402040

2041+
class SplitArgs(TypedDict, total=False):
2042+
comments: bool
2043+
posix: bool
2044+
2045+
20412046
class CommandSpec(list):
20422047
"""
20432048
A command spec for a #! header, specified as a list of arguments akin to
20442049
those passed to Popen.
20452050
"""
20462051

20472052
options: list[str] = []
2048-
split_args: dict[str, bool] = dict()
2053+
split_args = SplitArgs()
20492054

20502055
@classmethod
20512056
def best(cls):
@@ -2128,7 +2133,7 @@ def _render(items):
21282133

21292134

21302135
class WindowsCommandSpec(CommandSpec):
2131-
split_args = dict(posix=False)
2136+
split_args = SplitArgs(posix=False)
21322137

21332138

21342139
class ScriptWriter:

setuptools/msvc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
import os
1414
import os.path
1515
import platform
16-
from typing import TYPE_CHECKING
16+
from typing import TYPE_CHECKING, TypedDict
1717

1818
from more_itertools import unique_everseen
1919

2020
import distutils.errors
2121

22+
if TYPE_CHECKING:
23+
from typing_extensions import NotRequired
24+
2225
# https://github.com/python/mypy/issues/8166
2326
if not TYPE_CHECKING and platform.system() == 'Windows':
2427
import winreg
@@ -876,6 +879,14 @@ def _use_last_dir_name(path, prefix=''):
876879
return next(matching_dirs, None) or ''
877880

878881

882+
class EnvironmentDict(TypedDict):
883+
include: str
884+
lib: str
885+
libpath: str
886+
path: str
887+
py_vcruntime_redist: NotRequired[str | None]
888+
889+
879890
class EnvironmentInfo:
880891
"""
881892
Return environment variables for specified Microsoft Visual C++ version
@@ -1420,7 +1431,7 @@ def VCRuntimeRedist(self) -> str | None:
14201431
)
14211432
return next(filter(os.path.isfile, candidate_paths), None) # type: ignore[arg-type] #python/mypy#12682
14221433

1423-
def return_env(self, exists=True):
1434+
def return_env(self, exists: bool = True) -> EnvironmentDict:
14241435
"""
14251436
Return environment dict.
14261437
@@ -1434,7 +1445,7 @@ def return_env(self, exists=True):
14341445
dict
14351446
environment
14361447
"""
1437-
env = dict(
1448+
env = EnvironmentDict(
14381449
include=self._build_paths(
14391450
'include',
14401451
[

0 commit comments

Comments
 (0)