Skip to content

Commit bd6aad0

Browse files
[3.14] gh-133403: Check Tools/build/generate-build-details.py with mypy (GH-133735) (#133764)
gh-133403: Check `Tools/build/generate-build-details.py` with mypy (GH-133735) (cherry picked from commit cd2f234) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 5dddedf commit bd6aad0

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.github/workflows/mypy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- "Misc/mypy/**"
1616
- "Tools/build/compute-changes.py"
1717
- "Tools/build/generate_sbom.py"
18+
- "Tools/build/generate-build-details.py"
1819
- "Tools/build/verify_ensurepip_wheels.py"
1920
- "Tools/build/update_file.py"
2021
- "Tools/cases_generator/**"

Tools/build/generate-build-details.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Script initially imported from:
44
# https://github.com/FFY00/python-instrospection/blob/main/python_introspection/scripts/generate-build-details.py
55

6+
from __future__ import annotations
7+
68
import argparse
79
import collections
810
import importlib.machinery
@@ -11,19 +13,23 @@
1113
import sys
1214
import sysconfig
1315

16+
TYPE_CHECKING = False
17+
if TYPE_CHECKING:
18+
from typing import Any
19+
1420

15-
def version_info_to_dict(obj): # (object) -> dict[str, Any]
21+
def version_info_to_dict(obj: sys._version_info) -> dict[str, Any]:
1622
field_names = ('major', 'minor', 'micro', 'releaselevel', 'serial')
1723
return {field: getattr(obj, field) for field in field_names}
1824

1925

20-
def get_dict_key(container, key): # (dict[str, Any], str) -> dict[str, Any]
26+
def get_dict_key(container: dict[str, Any], key: str) -> dict[str, Any]:
2127
for part in key.split('.'):
2228
container = container[part]
2329
return container
2430

2531

26-
def generate_data(schema_version):
32+
def generate_data(schema_version: str) -> collections.defaultdict[str, Any]:
2733
"""Generate the build-details.json data (PEP 739).
2834
2935
:param schema_version: The schema version of the data we want to generate.
@@ -32,7 +38,9 @@ def generate_data(schema_version):
3238
if schema_version != '1.0':
3339
raise ValueError(f'Unsupported schema_version: {schema_version}')
3440

35-
data = collections.defaultdict(lambda: collections.defaultdict(dict))
41+
data: collections.defaultdict[str, Any] = collections.defaultdict(
42+
lambda: collections.defaultdict(dict),
43+
)
3644

3745
data['schema_version'] = schema_version
3846

@@ -122,7 +130,7 @@ def generate_data(schema_version):
122130
return data
123131

124132

125-
def make_paths_relative(data, config_path=None): # (dict[str, Any], str | None) -> None
133+
def make_paths_relative(data: dict[str, Any], config_path: str | None = None) -> None:
126134
# Make base_prefix relative to the config_path directory
127135
if config_path:
128136
data['base_prefix'] = os.path.relpath(data['base_prefix'], os.path.dirname(config_path))
@@ -152,7 +160,7 @@ def make_paths_relative(data, config_path=None): # (dict[str, Any], str | None)
152160
container[child] = new_path
153161

154162

155-
def main(): # () -> None
163+
def main() -> None:
156164
parser = argparse.ArgumentParser(exit_on_error=False)
157165
parser.add_argument('location')
158166
parser.add_argument(

Tools/build/mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# .github/workflows/mypy.yml
55
files =
66
Tools/build/compute-changes.py,
7+
Tools/build/generate-build-details.py,
78
Tools/build/generate_sbom.py,
89
Tools/build/verify_ensurepip_wheels.py,
910
Tools/build/update_file.py

0 commit comments

Comments
 (0)