Skip to content

Commit c99adf4

Browse files
authored
distutils: improve boolean parameters with int defaults (#11928)
1 parent 240114a commit c99adf4

26 files changed

+228
-141
lines changed

stdlib/distutils/archive_util.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
from typing import Literal
2+
13
def make_archive(
24
base_name: str,
35
format: str,
46
root_dir: str | None = None,
57
base_dir: str | None = None,
6-
verbose: int = 0,
7-
dry_run: int = 0,
8+
verbose: bool | Literal[0, 1] = 0,
9+
dry_run: bool | Literal[0, 1] = 0,
810
owner: str | None = None,
911
group: str | None = None,
1012
) -> str: ...
1113
def make_tarball(
1214
base_name: str,
1315
base_dir: str,
1416
compress: str | None = "gzip",
15-
verbose: int = 0,
16-
dry_run: int = 0,
17+
verbose: bool | Literal[0, 1] = 0,
18+
dry_run: bool | Literal[0, 1] = 0,
1719
owner: str | None = None,
1820
group: str | None = None,
1921
) -> str: ...
20-
def make_zipfile(base_name: str, base_dir: str, verbose: int = 0, dry_run: int = 0) -> str: ...
22+
def make_zipfile(base_name: str, base_dir: str, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0) -> str: ...

stdlib/distutils/ccompiler.pyi

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable
2-
from typing import Any
2+
from typing import Any, Literal
33
from typing_extensions import TypeAlias
44

55
_Macro: TypeAlias = tuple[str] | tuple[str, str | None]
@@ -10,7 +10,11 @@ def gen_lib_options(
1010
def gen_preprocess_options(macros: list[_Macro], include_dirs: list[str]) -> list[str]: ...
1111
def get_default_compiler(osname: str | None = None, platform: str | None = None) -> str: ...
1212
def new_compiler(
13-
plat: str | None = None, compiler: str | None = None, verbose: int = 0, dry_run: int = 0, force: int = 0
13+
plat: str | None = None,
14+
compiler: str | None = None,
15+
verbose: bool | Literal[0, 1] = 0,
16+
dry_run: bool | Literal[0, 1] = 0,
17+
force: bool | Literal[0, 1] = 0,
1418
) -> CCompiler: ...
1519
def show_compilers() -> None: ...
1620

@@ -25,7 +29,9 @@ class CCompiler:
2529
library_dirs: list[str]
2630
runtime_library_dirs: list[str]
2731
objects: list[str]
28-
def __init__(self, verbose: int = 0, dry_run: int = 0, force: int = 0) -> None: ...
32+
def __init__(
33+
self, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0, force: bool | Literal[0, 1] = 0
34+
) -> None: ...
2935
def add_include_dir(self, dir: str) -> None: ...
3036
def set_include_dirs(self, dirs: list[str]) -> None: ...
3137
def add_library(self, libname: str) -> None: ...
@@ -39,7 +45,7 @@ class CCompiler:
3945
def add_link_object(self, object: str) -> None: ...
4046
def set_link_objects(self, objects: list[str]) -> None: ...
4147
def detect_language(self, sources: str | list[str]) -> str | None: ...
42-
def find_library_file(self, dirs: list[str], lib: str, debug: bool = ...) -> str | None: ...
48+
def find_library_file(self, dirs: list[str], lib: str, debug: bool | Literal[0, 1] = 0) -> str | None: ...
4349
def has_function(
4450
self,
4551
funcname: str,
@@ -58,7 +64,7 @@ class CCompiler:
5864
output_dir: str | None = None,
5965
macros: list[_Macro] | None = None,
6066
include_dirs: list[str] | None = None,
61-
debug: bool = ...,
67+
debug: bool | Literal[0, 1] = 0,
6268
extra_preargs: list[str] | None = None,
6369
extra_postargs: list[str] | None = None,
6470
depends: list[str] | None = None,
@@ -68,7 +74,7 @@ class CCompiler:
6874
objects: list[str],
6975
output_libname: str,
7076
output_dir: str | None = None,
71-
debug: bool = ...,
77+
debug: bool | Literal[0, 1] = 0,
7278
target_lang: str | None = None,
7379
) -> None: ...
7480
def link(
@@ -81,7 +87,7 @@ class CCompiler:
8187
library_dirs: list[str] | None = None,
8288
runtime_library_dirs: list[str] | None = None,
8389
export_symbols: list[str] | None = None,
84-
debug: bool = ...,
90+
debug: bool | Literal[0, 1] = 0,
8591
extra_preargs: list[str] | None = None,
8692
extra_postargs: list[str] | None = None,
8793
build_temp: str | None = None,
@@ -95,7 +101,7 @@ class CCompiler:
95101
libraries: list[str] | None = None,
96102
library_dirs: list[str] | None = None,
97103
runtime_library_dirs: list[str] | None = None,
98-
debug: bool = ...,
104+
debug: bool | Literal[0, 1] = 0,
99105
extra_preargs: list[str] | None = None,
100106
extra_postargs: list[str] | None = None,
101107
target_lang: str | None = None,
@@ -109,7 +115,7 @@ class CCompiler:
109115
library_dirs: list[str] | None = None,
110116
runtime_library_dirs: list[str] | None = None,
111117
export_symbols: list[str] | None = None,
112-
debug: bool = ...,
118+
debug: bool | Literal[0, 1] = 0,
113119
extra_preargs: list[str] | None = None,
114120
extra_postargs: list[str] | None = None,
115121
build_temp: str | None = None,
@@ -124,7 +130,7 @@ class CCompiler:
124130
library_dirs: list[str] | None = None,
125131
runtime_library_dirs: list[str] | None = None,
126132
export_symbols: list[str] | None = None,
127-
debug: bool = ...,
133+
debug: bool | Literal[0, 1] = 0,
128134
extra_preargs: list[str] | None = None,
129135
extra_postargs: list[str] | None = None,
130136
build_temp: str | None = None,
@@ -139,10 +145,14 @@ class CCompiler:
139145
extra_preargs: list[str] | None = None,
140146
extra_postargs: list[str] | None = None,
141147
) -> None: ...
142-
def executable_filename(self, basename: str, strip_dir: int = 0, output_dir: str = "") -> str: ...
143-
def library_filename(self, libname: str, lib_type: str = "static", strip_dir: int = 0, output_dir: str = "") -> str: ...
144-
def object_filenames(self, source_filenames: list[str], strip_dir: int = 0, output_dir: str = "") -> list[str]: ...
145-
def shared_object_filename(self, basename: str, strip_dir: int = 0, output_dir: str = "") -> str: ...
148+
def executable_filename(self, basename: str, strip_dir: bool | Literal[0, 1] = 0, output_dir: str = "") -> str: ...
149+
def library_filename(
150+
self, libname: str, lib_type: str = "static", strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ""
151+
) -> str: ...
152+
def object_filenames(
153+
self, source_filenames: list[str], strip_dir: bool | Literal[0, 1] = 0, output_dir: str = ""
154+
) -> list[str]: ...
155+
def shared_object_filename(self, basename: str, strip_dir: bool | Literal[0, 1] = 0, output_dir: str = "") -> str: ...
146156
def execute(self, func: Callable[..., object], args: tuple[Any, ...], msg: str | None = None, level: int = 1) -> None: ...
147157
def spawn(self, cmd: list[str]) -> None: ...
148158
def mkpath(self, name: str, mode: int = 0o777) -> None: ...

stdlib/distutils/cmd.pyi

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import Incomplete, Unused
22
from abc import abstractmethod
33
from collections.abc import Callable, Iterable
44
from distutils.dist import Distribution
5-
from typing import Any
5+
from typing import Any, Literal
66

77
class Command:
88
distribution: Distribution
@@ -22,27 +22,33 @@ class Command:
2222
def ensure_dirname(self, option: str) -> None: ...
2323
def get_command_name(self) -> str: ...
2424
def set_undefined_options(self, src_cmd: str, *option_pairs: tuple[str, str]) -> None: ...
25-
def get_finalized_command(self, command: str, create: int = 1) -> Command: ...
26-
def reinitialize_command(self, command: Command | str, reinit_subcommands: int = 0) -> Command: ...
25+
def get_finalized_command(self, command: str, create: bool | Literal[0, 1] = 1) -> Command: ...
26+
def reinitialize_command(self, command: Command | str, reinit_subcommands: bool | Literal[0, 1] = 0) -> Command: ...
2727
def run_command(self, command: str) -> None: ...
2828
def get_sub_commands(self) -> list[str]: ...
2929
def warn(self, msg: str) -> None: ...
3030
def execute(self, func: Callable[..., object], args: Iterable[Any], msg: str | None = None, level: int = 1) -> None: ...
3131
def mkpath(self, name: str, mode: int = 0o777) -> None: ...
3232
def copy_file(
33-
self, infile: str, outfile: str, preserve_mode: int = 1, preserve_times: int = 1, link: str | None = None, level: Any = 1
34-
) -> tuple[str, bool]: ... # level is not used
33+
self,
34+
infile: str,
35+
outfile: str,
36+
preserve_mode: bool | Literal[0, 1] = 1,
37+
preserve_times: bool | Literal[0, 1] = 1,
38+
link: str | None = None,
39+
level: Unused = 1,
40+
) -> tuple[str, bool]: ...
3541
def copy_tree(
3642
self,
3743
infile: str,
3844
outfile: str,
39-
preserve_mode: int = 1,
40-
preserve_times: int = 1,
41-
preserve_symlinks: int = 0,
42-
level: Any = 1,
43-
) -> list[str]: ... # level is not used
44-
def move_file(self, src: str, dst: str, level: Any = 1) -> str: ... # level is not used
45-
def spawn(self, cmd: Iterable[str], search_path: int = 1, level: Any = 1) -> None: ... # level is not used
45+
preserve_mode: bool | Literal[0, 1] = 1,
46+
preserve_times: bool | Literal[0, 1] = 1,
47+
preserve_symlinks: bool | Literal[0, 1] = 0,
48+
level: Unused = 1,
49+
) -> list[str]: ...
50+
def move_file(self, src: str, dst: str, level: Unused = 1) -> str: ...
51+
def spawn(self, cmd: Iterable[str], search_path: bool | Literal[0, 1] = 1, level: Unused = 1) -> None: ...
4652
def make_archive(
4753
self,
4854
base_name: str,
@@ -60,7 +66,7 @@ class Command:
6066
args: list[Any],
6167
exec_msg: str | None = None,
6268
skip_msg: str | None = None,
63-
level: Any = 1,
64-
) -> None: ... # level is not used
69+
level: Unused = 1,
70+
) -> None: ...
6571
def ensure_finalized(self) -> None: ...
6672
def dump_options(self, header: Incomplete | None = None, indent: str = "") -> None: ...

stdlib/distutils/command/bdist_msi.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import Any
2+
from typing import Any, Literal
33

44
from ..cmd import Command
55

@@ -9,9 +9,9 @@ if sys.platform == "win32":
99
class PyDialog(Dialog):
1010
def __init__(self, *args, **kw) -> None: ...
1111
def title(self, title) -> None: ...
12-
def back(self, title, next, name: str = "Back", active: int = 1): ...
13-
def cancel(self, title, next, name: str = "Cancel", active: int = 1): ...
14-
def next(self, title, next, name: str = "Next", active: int = 1): ...
12+
def back(self, title, next, name: str = "Back", active: bool | Literal[0, 1] = 1): ...
13+
def cancel(self, title, next, name: str = "Cancel", active: bool | Literal[0, 1] = 1): ...
14+
def next(self, title, next, name: str = "Next", active: bool | Literal[0, 1] = 1): ...
1515
def xbutton(self, name, title, next, xpos): ...
1616

1717
class bdist_msi(Command):

stdlib/distutils/command/build_py.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Literal
22

33
from ..cmd import Command
44
from ..util import Mixin2to3 as Mixin2to3
@@ -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: int = 1): ...
35+
def get_outputs(self, include_bytecode: bool | Literal[0, 1] = 1): ...
3636
def build_module(self, module, module_file, package): ...
3737
def build_modules(self) -> None: ...
3838
def build_packages(self) -> None: ...

stdlib/distutils/command/check.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Literal
22
from typing_extensions import TypeAlias
33

44
from ..cmd import Command
@@ -16,7 +16,7 @@ class SilentReporter(_Reporter):
1616
report_level,
1717
halt_level,
1818
stream: Any | None = ...,
19-
debug: int = ...,
19+
debug: bool | Literal[0, 1] = 0,
2020
encoding: str = ...,
2121
error_handler: str = ...,
2222
) -> None: ...

stdlib/distutils/command/config.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Sequence
22
from re import Pattern
3-
from typing import Any
3+
from typing import Any, Literal
44

55
from ..ccompiler import CCompiler
66
from ..cmd import Command
@@ -65,8 +65,8 @@ class config(Command):
6565
include_dirs: Sequence[str] | None = None,
6666
libraries: Sequence[str] | None = None,
6767
library_dirs: Sequence[str] | None = None,
68-
decl: int = 0,
69-
call: int = 0,
68+
decl: bool | Literal[0, 1] = 0,
69+
call: bool | Literal[0, 1] = 0,
7070
) -> bool: ...
7171
def check_lib(
7272
self,

stdlib/distutils/core.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from collections.abc import Mapping
33
from distutils.cmd import Command as Command
44
from distutils.dist import Distribution as Distribution
55
from distutils.extension import Extension as Extension
6-
from typing import Any
6+
from typing import Any, Literal
77

88
USAGE: str
99

@@ -45,7 +45,7 @@ def setup(
4545
command_packages: list[str] = ...,
4646
command_options: Mapping[str, Mapping[str, tuple[Any, Any]]] = ...,
4747
package_data: Mapping[str, list[str]] = ...,
48-
include_package_data: bool = ...,
48+
include_package_data: bool | Literal[0, 1] = ...,
4949
libraries: list[str] = ...,
5050
headers: list[str] = ...,
5151
ext_package: str = ...,

stdlib/distutils/dir_util.pyi

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
def mkpath(name: str, mode: int = 0o777, verbose: int = 1, dry_run: int = 0) -> list[str]: ...
2-
def create_tree(base_dir: str, files: list[str], mode: int = 0o777, verbose: int = 1, dry_run: int = 0) -> None: ...
1+
from typing import Literal
2+
3+
def mkpath(name: str, mode: int = 0o777, verbose: bool | Literal[0, 1] = 1, dry_run: bool | Literal[0, 1] = 0) -> list[str]: ...
4+
def create_tree(
5+
base_dir: str, files: list[str], mode: int = 0o777, verbose: bool | Literal[0, 1] = 1, dry_run: bool | Literal[0, 1] = 0
6+
) -> None: ...
37
def copy_tree(
48
src: str,
59
dst: str,
6-
preserve_mode: int = 1,
7-
preserve_times: int = 1,
8-
preserve_symlinks: int = 0,
9-
update: int = 0,
10-
verbose: int = 1,
11-
dry_run: int = 0,
10+
preserve_mode: bool | Literal[0, 1] = 1,
11+
preserve_times: bool | Literal[0, 1] = 1,
12+
preserve_symlinks: bool | Literal[0, 1] = 0,
13+
update: bool | Literal[0, 1] = 0,
14+
verbose: bool | Literal[0, 1] = 1,
15+
dry_run: bool | Literal[0, 1] = 0,
1216
) -> list[str]: ...
13-
def remove_tree(directory: str, verbose: int = 1, dry_run: int = 0) -> None: ...
17+
def remove_tree(directory: str, verbose: bool | Literal[0, 1] = 1, dry_run: bool | Literal[0, 1] = 0) -> None: ...

stdlib/distutils/file_util.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from collections.abc import Sequence
2+
from typing import Literal
23

34
def copy_file(
45
src: str,
56
dst: str,
6-
preserve_mode: bool = ...,
7-
preserve_times: bool = ...,
8-
update: bool = ...,
7+
preserve_mode: bool | Literal[0, 1] = 1,
8+
preserve_times: bool | Literal[0, 1] = 1,
9+
update: bool | Literal[0, 1] = 0,
910
link: str | None = None,
10-
verbose: bool = ...,
11-
dry_run: bool = ...,
11+
verbose: bool | Literal[0, 1] = 1,
12+
dry_run: bool | Literal[0, 1] = 0,
1213
) -> tuple[str, str]: ...
13-
def move_file(src: str, dst: str, verbose: bool = ..., dry_run: bool = ...) -> str: ...
14+
def move_file(src: str, dst: str, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0) -> str: ...
1415
def write_file(filename: str, contents: Sequence[str]) -> None: ...

stdlib/distutils/filelist.pyi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class FileList:
2323
def include_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1]) -> bool: ...
2424
@overload
2525
def include_pattern(
26-
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = 1, prefix: str | None = None, is_regex: int = 0
26+
self,
27+
pattern: str | Pattern[str],
28+
anchor: bool | Literal[0, 1] = 1,
29+
prefix: str | None = None,
30+
is_regex: bool | Literal[0, 1] = 0,
2731
) -> bool: ...
2832
@overload
2933
def exclude_pattern(
@@ -33,7 +37,11 @@ class FileList:
3337
def exclude_pattern(self, pattern: str | Pattern[str], *, is_regex: Literal[True, 1]) -> bool: ...
3438
@overload
3539
def exclude_pattern(
36-
self, pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = 1, prefix: str | None = None, is_regex: int = 0
40+
self,
41+
pattern: str | Pattern[str],
42+
anchor: bool | Literal[0, 1] = 1,
43+
prefix: str | None = None,
44+
is_regex: bool | Literal[0, 1] = 0,
3745
) -> bool: ...
3846

3947
def findall(dir: str = ".") -> list[str]: ...
@@ -46,5 +54,5 @@ def translate_pattern(
4654
def translate_pattern(pattern: str | Pattern[str], *, is_regex: Literal[True, 1]) -> Pattern[str]: ...
4755
@overload
4856
def translate_pattern(
49-
pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = 1, prefix: str | None = None, is_regex: int = 0
57+
pattern: str | Pattern[str], anchor: bool | Literal[0, 1] = 1, prefix: str | None = None, is_regex: bool | Literal[0, 1] = 0
5058
) -> Pattern[str]: ...

stdlib/distutils/spawn.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
def spawn(cmd: list[str], search_path: bool = ..., verbose: bool = ..., dry_run: bool = ...) -> None: ...
1+
from typing import Literal
2+
3+
def spawn(
4+
cmd: list[str], search_path: bool | Literal[0, 1] = 1, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0
5+
) -> None: ...
26
def find_executable(executable: str, path: str | None = None) -> str | None: ...

stdlib/distutils/sysconfig.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def get_config_vars() -> dict[str, str | int]: ...
2323
def get_config_vars(arg: str, /, *args: str) -> list[str | int]: ...
2424
def get_config_h_filename() -> str: ...
2525
def get_makefile_filename() -> str: ...
26-
def get_python_inc(plat_specific: bool = ..., prefix: str | None = None) -> str: ...
27-
def get_python_lib(plat_specific: bool = ..., standard_lib: bool = ..., prefix: str | None = None) -> str: ...
26+
def get_python_inc(plat_specific: bool | Literal[0, 1] = 0, prefix: str | None = None) -> str: ...
27+
def get_python_lib(
28+
plat_specific: bool | Literal[0, 1] = 0, standard_lib: bool | Literal[0, 1] = 0, prefix: str | None = None
29+
) -> str: ...
2830
def customize_compiler(compiler: CCompiler) -> None: ...
2931

3032
if sys.version_info < (3, 10):

0 commit comments

Comments
 (0)