Skip to content

Commit 0353c55

Browse files
committed
Merge TypedDict from typeshed
1 parent f410da1 commit 0353c55

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

setuptools/command/easy_install.py

+8-3
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, NoReturn, TypeVar
37+
from typing import TYPE_CHECKING, Callable, NoReturn, TypedDict, TypeVar
3838

3939
from jaraco.text import yield_lines
4040

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

20412041

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

20482053
options: list[str] = []
2049-
split_args: dict[str, bool] = dict()
2054+
split_args = _SplitArgs()
20502055

20512056
@classmethod
20522057
def best(cls):
@@ -2129,7 +2134,7 @@ def _render(items):
21292134

21302135

21312136
class WindowsCommandSpec(CommandSpec):
2132-
split_args = dict(posix=False)
2137+
split_args = _SplitArgs(posix=False)
21332138

21342139

21352140
class ScriptWriter:

setuptools/command/install.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ def _called_from_setup(run_frame):
137137
return False
138138

139139
def do_egg_install(self) -> None:
140-
easy_install = self.distribution.get_command_class('easy_install')
140+
easy_install = cast(
141+
type[easy_install_cls], self.distribution.get_command_class('easy_install')
142+
)
141143

142144
cmd = cast(
143145
# We'd want to cast easy_install as type[easy_install_cls] but a bug in

setuptools/msvc.py

+14-3
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)