Skip to content

Commit dc115d9

Browse files
committed
Fixups and use Incomplete instead of Any
1 parent 14b2864 commit dc115d9

29 files changed

+253
-167
lines changed

Diff for: setuptools/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
"""Extensions to the 'distutils' for large or complex distributions"""
2-
# mypy: disable_error_code=override
3-
# Command.reinitialize_command has an extra **kw param that distutils doesn't have
4-
# Can't disable on the exact line because distutils doesn't exists on Python 3.12
5-
# and mypy isn't aware of distutils_hack, causing distutils.core.Command to be Any,
6-
# and a [unused-ignore] to be raised on 3.12+
72

83
from __future__ import annotations
94

@@ -215,7 +210,7 @@ def ensure_string_list(self, option):
215210
"'%s' must be a list of strings (got %r)" % (option, val)
216211
)
217212

218-
@overload
213+
@overload # type: ignore[override] # Has an extra **kw param that distutils doesn't have
219214
def reinitialize_command(
220215
self, command: str, reinit_subcommands: bool = False, **kw
221216
) -> _Command: ...

Diff for: setuptools/command/editable_wheel.py

-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ def _set_editable_mode(self):
231231
"""Set the ``editable_mode`` flag in the build sub-commands"""
232232
dist = self.distribution
233233
build = dist.get_command_obj("build")
234-
# TODO: Update typeshed distutils stubs to overload non-None return type by default
235234
for cmd_name in build.get_sub_commands():
236235
cmd = dist.get_command_obj(cmd_name)
237236
if hasattr(cmd, "editable_mode"):

Diff for: setuptools/config/setupcfg.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
Generic,
2525
Iterable,
2626
Iterator,
27-
List,
2827
Tuple,
2928
TypeVar,
30-
cast,
3129
)
3230

3331
from packaging.markers import default_environment as marker_env
@@ -109,8 +107,7 @@ def _apply(
109107
filenames = [*other_files, filepath]
110108

111109
try:
112-
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
113-
_Distribution.parse_config_files(dist, filenames=cast(List[str], filenames))
110+
_Distribution.parse_config_files(dist, filenames=filenames)
114111
handlers = parse_configuration(
115112
dist, dist.command_options, ignore_option_errors=ignore_option_errors
116113
)

Diff for: typings/distutils-stubs/__init__.pyi

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
# Attempts to improve these stubs are probably not the best use of time:
2-
# - distutils is deleted in Python 3.12 and newer
3-
# - Most users already do not use stdlib distutils, due to setuptools monkeypatching
4-
# - We have very little quality assurance on these stubs, since due to the two above issues
5-
# we allowlist all distutils errors in stubtest.

Diff for: typings/distutils-stubs/ccompiler.pyi

+49-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from _typeshed import BytesPath, StrPath, Unused
21
from collections.abc import Callable, Iterable
32
from typing import ClassVar, Literal, TypeVar, overload
3+
4+
from _typeshed import BytesPath, StrPath, Unused
45
from typing_extensions import TypeAlias, TypeVarTuple, Unpack
56

67
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
@@ -9,12 +10,23 @@ _BytesPathT = TypeVar("_BytesPathT", bound=BytesPath)
910
_Ts = TypeVarTuple("_Ts")
1011

1112
def gen_lib_options(
12-
compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str]
13+
compiler: CCompiler,
14+
library_dirs: list[str],
15+
runtime_library_dirs: list[str],
16+
libraries: list[str],
1317
) -> list[str]: ...
14-
def gen_preprocess_options(macros: list[_Macro], include_dirs: list[str]) -> list[str]: ...
15-
def get_default_compiler(osname: str | None = None, platform: str | None = None) -> str: ...
18+
def gen_preprocess_options(
19+
macros: list[_Macro], include_dirs: list[str]
20+
) -> list[str]: ...
21+
def get_default_compiler(
22+
osname: str | None = None, platform: str | None = None
23+
) -> str: ...
1624
def new_compiler(
17-
plat: str | None = None, compiler: str | None = None, verbose: bool = False, dry_run: bool = False, force: bool = False
25+
plat: str | None = None,
26+
compiler: str | None = None,
27+
verbose: bool = False,
28+
dry_run: bool = False,
29+
force: bool = False,
1830
) -> CCompiler: ...
1931
def show_compilers() -> None: ...
2032

@@ -38,7 +50,9 @@ class CCompiler:
3850
library_dirs: list[str]
3951
runtime_library_dirs: list[str]
4052
objects: list[str]
41-
def __init__(self, verbose: bool = False, dry_run: bool = False, force: bool = False) -> None: ...
53+
def __init__(
54+
self, verbose: bool = False, dry_run: bool = False, force: bool = False
55+
) -> None: ...
4256
def add_include_dir(self, dir: str) -> None: ...
4357
def set_include_dirs(self, dirs: list[str]) -> None: ...
4458
def add_library(self, libname: str) -> None: ...
@@ -52,7 +66,9 @@ class CCompiler:
5266
def add_link_object(self, object: str) -> None: ...
5367
def set_link_objects(self, objects: list[str]) -> None: ...
5468
def detect_language(self, sources: str | list[str]) -> str | None: ...
55-
def find_library_file(self, dirs: list[str], lib: str, debug: bool = False) -> str | None: ...
69+
def find_library_file(
70+
self, dirs: list[str], lib: str, debug: bool = False
71+
) -> str | None: ...
5672
def has_function(
5773
self,
5874
funcname: str,
@@ -153,21 +169,40 @@ class CCompiler:
153169
extra_postargs: list[str] | None = None,
154170
) -> None: ...
155171
@overload
156-
def executable_filename(self, basename: str, strip_dir: Literal[0, False] = 0, output_dir: StrPath = "") -> str: ...
172+
def executable_filename(
173+
self, basename: str, strip_dir: Literal[False] = False, output_dir: StrPath = ""
174+
) -> str: ...
157175
@overload
158-
def executable_filename(self, basename: StrPath, strip_dir: Literal[1, True], output_dir: StrPath = "") -> str: ...
176+
def executable_filename(
177+
self, basename: StrPath, strip_dir: Literal[True], output_dir: StrPath = ""
178+
) -> str: ...
159179
def library_filename(
160-
self, libname: str, lib_type: str = "static", strip_dir: bool = False, output_dir: StrPath = ""
180+
self,
181+
libname: str,
182+
lib_type: str = "static",
183+
strip_dir: bool = False,
184+
output_dir: StrPath = "",
161185
) -> str: ...
162186
def object_filenames(
163-
self, source_filenames: Iterable[StrPath], strip_dir: bool = False, output_dir: StrPath | None = None
187+
self,
188+
source_filenames: Iterable[StrPath],
189+
strip_dir: bool = False,
190+
output_dir: StrPath | None = '',
164191
) -> list[str]: ...
165192
@overload
166-
def shared_object_filename(self, basename: str, strip_dir: Literal[0, False] = 0, output_dir: StrPath = "") -> str: ...
193+
def shared_object_filename(
194+
self, basename: str, strip_dir: Literal[False] = False, output_dir: StrPath = ""
195+
) -> str: ...
167196
@overload
168-
def shared_object_filename(self, basename: StrPath, strip_dir: Literal[1, True], output_dir: StrPath = "") -> str: ...
197+
def shared_object_filename(
198+
self, basename: StrPath, strip_dir: Literal[True], output_dir: StrPath = ""
199+
) -> str: ...
169200
def execute(
170-
self, func: Callable[[Unpack[_Ts]], Unused], args: tuple[Unpack[_Ts]], msg: str | None = None, level: int = 1
201+
self,
202+
func: Callable[[Unpack[_Ts]], Unused],
203+
args: tuple[Unpack[_Ts]],
204+
msg: str | None = None,
205+
level: int = 1,
171206
) -> None: ...
172207
def spawn(self, cmd: list[str]) -> None: ...
173208
def mkpath(self, name: str, mode: int = 0o777) -> None: ...

Diff for: typings/distutils-stubs/cmd.pyi

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ from distutils.command.register import register
2323
from distutils.command.sdist import sdist
2424
from distutils.command.upload import upload
2525
from distutils.dist import Distribution
26-
from distutils.file_util import _BytesPathT, _StrPathT
2726
from typing import Any, ClassVar, Literal, TypeVar, overload
2827
from typing_extensions import TypeVarTuple, Unpack
2928

Diff for: typings/distutils-stubs/command/bdist_dumb.pyi

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
23

34
from ..cmd import Command
45

@@ -7,15 +8,15 @@ class bdist_dumb(Command):
78
user_options: ClassVar[list[tuple[str, str | None, str]]]
89
boolean_options: ClassVar[list[str]]
910
default_format: ClassVar[dict[str, str]]
10-
bdist_dir: Any
11-
plat_name: Any
12-
format: Any
11+
bdist_dir: Incomplete
12+
plat_name: Incomplete
13+
format: Incomplete
1314
keep_temp: int
14-
dist_dir: Any
15-
skip_build: Any
15+
dist_dir: Incomplete
16+
skip_build: Incomplete
1617
relative: int
17-
owner: Any
18-
group: Any
18+
owner: Incomplete
19+
group: Incomplete
1920
def initialize_options(self) -> None: ...
2021
def finalize_options(self) -> None: ...
2122
def run(self) -> None: ...

Diff for: typings/distutils-stubs/command/build_py.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class build_py(Command):
3232
def find_all_modules(self): ...
3333
def get_source_files(self): ...
3434
def get_module_outfile(self, build_dir, package, module): ...
35-
def get_outputs(self, include_bytecode: bool = True): ...
35+
def get_outputs(self, include_bytecode: bool = True) -> list[str]: ...
3636
def build_module(self, module, module_file, package): ...
3737
def build_modules(self) -> None: ...
3838
def build_packages(self) -> None: ...

Diff for: typings/distutils-stubs/command/build_scripts.pyi

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
23

34
from ..cmd import Command
4-
from ..util import Mixin2to3 as Mixin2to3
55

6-
first_line_re: Any
6+
first_line_re: Incomplete
77

88
class build_scripts(Command):
99
description: str
1010
user_options: ClassVar[list[tuple[str, str, str]]]
1111
boolean_options: ClassVar[list[str]]
12-
build_dir: Any
13-
scripts: Any
14-
force: Any
15-
executable: Any
16-
outfiles: Any
12+
build_dir: Incomplete
13+
scripts: Incomplete
14+
force: Incomplete
15+
executable: Incomplete
16+
outfiles: Incomplete
1717
def initialize_options(self) -> None: ...
1818
def finalize_options(self) -> None: ...
1919
def get_source_files(self): ...
2020
def run(self) -> None: ...
2121
def copy_scripts(self): ...
22-
23-
class build_scripts_2to3(build_scripts, Mixin2to3):
24-
def copy_scripts(self): ...

Diff for: typings/distutils-stubs/command/check.pyi

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
from typing import Any, ClassVar, Final, Literal
2-
from typing_extensions import TypeAlias
1+
from typing import ClassVar, Final
32

4-
from ..cmd import Command
3+
from _typeshed import Incomplete
4+
from docutils.utils import Reporter
55

6-
_Reporter: TypeAlias = Any # really docutils.utils.Reporter
6+
from ..cmd import Command
77

8-
# Only defined if docutils is installed.
9-
# Depends on a third-party stub. Since distutils is deprecated anyway,
10-
# it's easier to just suppress the "any subclassing" error.
11-
class SilentReporter(_Reporter):
12-
messages: Any
8+
class SilentReporter(Reporter):
9+
messages: Incomplete
1310
def __init__(
1411
self,
1512
source,
1613
report_level,
1714
halt_level,
18-
stream: Any | None = ...,
19-
debug: bool | Literal[0, 1] = 0,
15+
stream: Incomplete | None = ...,
16+
debug: bool = False,
2017
encoding: str = ...,
2118
error_handler: str = ...,
2219
) -> None: ...

Diff for: typings/distutils-stubs/command/clean.pyi

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
23

34
from ..cmd import Command
45

56
class clean(Command):
67
description: str
78
user_options: ClassVar[list[tuple[str, str | None, str]]]
89
boolean_options: ClassVar[list[str]]
9-
build_base: Any
10-
build_lib: Any
11-
build_temp: Any
12-
build_scripts: Any
13-
bdist_base: Any
14-
all: Any
10+
build_base: Incomplete
11+
build_lib: Incomplete
12+
build_temp: Incomplete
13+
build_scripts: Incomplete
14+
bdist_base: Incomplete
15+
all: Incomplete
1516
def initialize_options(self) -> None: ...
1617
def finalize_options(self) -> None: ...
1718
def run(self) -> None: ...

Diff for: typings/distutils-stubs/command/config.pyi

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from _typeshed import StrOrBytesPath
21
from collections.abc import Sequence
32
from re import Pattern
4-
from typing import Any, ClassVar, Final, Literal
3+
from typing import ClassVar, Final
4+
5+
from _typeshed import Incomplete, StrOrBytesPath
56

67
from ..ccompiler import CCompiler
78
from ..cmd import Command
@@ -39,7 +40,11 @@ class config(Command):
3940
lang: str = "c",
4041
) -> bool: ...
4142
def try_compile(
42-
self, body: str, headers: Sequence[str] | None = None, include_dirs: Sequence[str] | None = None, lang: str = "c"
43+
self,
44+
body: str,
45+
headers: Sequence[str] | None = None,
46+
include_dirs: Sequence[str] | None = None,
47+
lang: str = "c",
4348
) -> bool: ...
4449
def try_link(
4550
self,
@@ -66,8 +71,8 @@ class config(Command):
6671
include_dirs: Sequence[str] | None = None,
6772
libraries: Sequence[str] | None = None,
6873
library_dirs: Sequence[str] | None = None,
69-
decl: bool | Literal[0, 1] = 0,
70-
call: bool | Literal[0, 1] = 0,
74+
decl: bool = False,
75+
call: bool = False,
7176
) -> bool: ...
7277
def check_lib(
7378
self,
@@ -78,7 +83,11 @@ class config(Command):
7883
other_libraries: list[str] = [],
7984
) -> bool: ...
8085
def check_header(
81-
self, header: str, include_dirs: Sequence[str] | None = None, library_dirs: Sequence[str] | None = None, lang: str = "c"
86+
self,
87+
header: str,
88+
include_dirs: Sequence[str] | None = None,
89+
library_dirs: Sequence[str] | None = None,
90+
lang: str = "c",
8291
) -> bool: ...
8392

84-
def dump_file(filename: StrOrBytesPath, head: Any | None = None) -> None: ...
93+
def dump_file(filename: StrOrBytesPath, head: Incomplete | None = None) -> None: ...

Diff for: typings/distutils-stubs/command/install_data.pyi

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
23

34
from ..cmd import Command
45

56
class install_data(Command):
67
description: str
78
user_options: ClassVar[list[tuple[str, str | None, str]]]
89
boolean_options: ClassVar[list[str]]
9-
install_dir: Any
10-
outfiles: Any
11-
root: Any
10+
install_dir: Incomplete
11+
outfiles: Incomplete
12+
root: Incomplete
1213
force: int
13-
data_files: Any
14+
data_files: Incomplete
1415
warn_dir: int
1516
def initialize_options(self) -> None: ...
1617
def finalize_options(self) -> None: ...

Diff for: typings/distutils-stubs/command/install_egg_info.pyi

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from typing import Any, ClassVar
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
23

34
from ..cmd import Command
45

56
class install_egg_info(Command):
67
description: ClassVar[str]
78
user_options: ClassVar[list[tuple[str, str, str]]]
8-
install_dir: Any
9+
install_dir: Incomplete
910
def initialize_options(self) -> None: ...
10-
target: Any
11-
outputs: Any
11+
target: Incomplete
12+
outputs: Incomplete
1213
def finalize_options(self) -> None: ...
1314
def run(self) -> None: ...
1415
def get_outputs(self) -> list[str]: ...

0 commit comments

Comments
 (0)