Skip to content

Commit 7940888

Browse files
authored
Added missing typings. (opensearch-project#2123)
* Added missing typings. Signed-off-by: dblock <dblock@amazon.com> * Added missing __init__ annotations. Signed-off-by: dblock <dblock@amazon.com> * Use dict instead of Any in manifest arguments. Signed-off-by: dblock <dblock@amazon.com> * Removed unused imports. Signed-off-by: dblock <dblock@amazon.com>
1 parent f880b58 commit 7940888

File tree

129 files changed

+1282
-827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1282
-827
lines changed

.github/workflows/python-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
pipenv run flake8 .
3333
- name: Run Type Checker
3434
run: |
35-
pipenv run mypy src/build_workflow tests/tests_build_workflow src/checkout_workflow tests/tests_checkout_workflow src/run_assemble.py tests/test_run_assemble.py src/assemble_workflow tests/tests_assemble_workflow src/manifests tests/tests_manifests src/paths tests/tests_paths src/system tests/tests_system src/ci_workflow tests/tests_ci_workflow src/manifests_workflow tests/tests_manifests_workflow
35+
pipenv run mypy .
3636
- name: Run Tests with Coverage
3737
run: |
3838
pipenv run coverage run -m pytest --cov=./src --cov-report=xml

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
- id: mypy
2020
stages: [commit]
2121
name: mypy
22-
entry: bash -c 'pipenv run mypy src/build_workflow tests/tests_build_workflow src/checkout_workflow tests/tests_checkout_workflow src/run_assemble.py tests/test_run_assemble.py src/assemble_workflow tests/tests_assemble_workflow src/manifests tests/tests_manifests src/paths tests/tests_paths src/system tests/tests_system src/ci_workflow tests/tests_ci_workflow src/manifests_workflow tests/tests_manifests_workflow'
22+
entry: bash -c 'pipenv run mypy .'
2323
language: system
2424
- id: pytest
2525
stages: [commit]

src/build_workflow/build_recorder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class BuildRecorder:
19-
def __init__(self, target: BuildTarget):
19+
def __init__(self, target: BuildTarget) -> None:
2020
self.build_manifest = self.BuildManifestBuilder(target)
2121
self.target = target
2222
self.name = target.name
@@ -52,7 +52,7 @@ def write_manifest(self) -> None:
5252
logging.info(f"Created build manifest {manifest_path}")
5353

5454
class BuildManifestBuilder:
55-
def __init__(self, target: BuildTarget):
55+
def __init__(self, target: BuildTarget) -> None:
5656
self.data: Dict[str, Any] = {}
5757
self.data["build"] = {}
5858
self.data["build"]["id"] = target.build_id

src/build_workflow/build_target.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434
snapshot: bool = True,
3535
build_id: str = None,
3636
output_dir: str = "artifacts",
37-
):
37+
) -> None:
3838
self.build_id = os.getenv("BUILD_NUMBER") or build_id or uuid.uuid4().hex
3939
self.name = name
4040
self.version = version

src/build_workflow/builder.py

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313

1414
class Builder(ABC):
15+
component: Any
16+
target: BuildTarget
17+
output_path: str
18+
1519
def __init__(self, component: Any, target: BuildTarget) -> None:
1620
self.output_path = "builds"
1721
self.component = component

src/ci_workflow/ci_check_list_source.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def checkout(self, work_dir: str) -> None:
3131
}
3232

3333
class InvalidCheckError(Exception):
34-
def __init__(self, check: Any):
34+
def __init__(self, check: Any) -> None:
3535
self.check = check
3636
super().__init__(f"Invalid check: {check.name}, must be one of {CiCheckListSource.CHECKS.keys()}.")
3737

src/manifests/build/build_manifest_1_0.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# this file be licensed under the Apache-2.0 license or a
55
# compatible open source license.
66

7-
from typing import Any
8-
97
from manifests.component_manifest import Component, ComponentManifest, Components
108

119
"""
@@ -75,7 +73,7 @@ class BuildManifest_1_0(ComponentManifest['BuildManifest_1_0', 'BuildComponents_
7573
},
7674
}
7775

78-
def __init__(self, data: Any):
76+
def __init__(self, data: dict) -> None:
7977
super().__init__(data)
8078
self.build = self.Build(data["build"])
8179
self.components = BuildComponents_1_0(data.get("components", [])) # type: ignore[assignment]
@@ -88,7 +86,7 @@ def __to_dict__(self) -> dict:
8886
}
8987

9088
class Build:
91-
def __init__(self, data: Any):
89+
def __init__(self, data: dict) -> None:
9290
self.name: str = data["name"]
9391
self.version = data["version"]
9492
self.architecture = data["architecture"]
@@ -109,12 +107,12 @@ def filename(self) -> str:
109107

110108
class BuildComponents_1_0(Components['BuildComponent_1_0']):
111109
@classmethod
112-
def __create__(self, data: Any) -> 'BuildComponent_1_0':
110+
def __create__(self, data: dict) -> 'BuildComponent_1_0':
113111
return BuildComponent_1_0(data)
114112

115113

116114
class BuildComponent_1_0(Component):
117-
def __init__(self, data: Any):
115+
def __init__(self, data: dict) -> None:
118116
super().__init__(data)
119117
self.repository = data["repository"]
120118
self.ref = data["ref"]

src/manifests/build/build_manifest_1_1.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# this file be licensed under the Apache-2.0 license or a
55
# compatible open source license.
66

7-
from typing import Any
8-
97
from manifests.component_manifest import Component, ComponentManifest, Components
108

119
"""
@@ -76,7 +74,7 @@ class BuildManifest_1_1(ComponentManifest['BuildManifest_1_1', 'BuildComponents_
7674
},
7775
}
7876

79-
def __init__(self, data: Any):
77+
def __init__(self, data: dict) -> None:
8078
super().__init__(data)
8179
self.build = self.Build(data["build"])
8280
self.components = BuildComponents_1_1(data.get("components", [])) # type: ignore[assignment]
@@ -89,7 +87,7 @@ def __to_dict__(self) -> dict:
8987
}
9088

9189
class Build:
92-
def __init__(self, data: Any):
90+
def __init__(self, data: dict) -> None:
9391
self.name: str = data["name"]
9492
self.version = data["version"]
9593
self.architecture = data["architecture"]
@@ -110,12 +108,12 @@ def filename(self) -> str:
110108

111109
class BuildComponents_1_1(Components['BuildComponent_1_1']):
112110
@classmethod
113-
def __create__(self, data: Any) -> 'BuildComponent_1_1':
111+
def __create__(self, data: dict) -> 'BuildComponent_1_1':
114112
return BuildComponent_1_1(data)
115113

116114

117115
class BuildComponent_1_1(Component):
118-
def __init__(self, data: Any):
116+
def __init__(self, data: dict) -> None:
119117
super().__init__(data)
120118
self.repository = data["repository"]
121119
self.ref = data["ref"]

src/manifests/build_manifest.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# this file be licensed under the Apache-2.0 license or a
55
# compatible open source license.
66

7-
from typing import Any
8-
97
from manifests.build.build_manifest_1_0 import BuildManifest_1_0
108
from manifests.build.build_manifest_1_1 import BuildManifest_1_1
119
from manifests.component_manifest import Component, ComponentManifest, Components
@@ -89,7 +87,7 @@ class BuildManifest(ComponentManifest['BuildManifest', 'BuildComponents']):
8987
},
9088
}
9189

92-
def __init__(self, data: Any):
90+
def __init__(self, data: dict) -> None:
9391
super().__init__(data)
9492
self.build = self.Build(data["build"])
9593
self.components = BuildComponents(data.get("components", [])) # type: ignore[assignment]
@@ -102,7 +100,7 @@ def __to_dict__(self) -> dict:
102100
}
103101

104102
class Build:
105-
def __init__(self, data: Any):
103+
def __init__(self, data: dict) -> None:
106104
self.name: str = data["name"]
107105
self.version: str = data["version"]
108106
self.platform: str = data["platform"]
@@ -127,12 +125,12 @@ def filename(self) -> str:
127125

128126
class BuildComponents(Components['BuildComponent']):
129127
@classmethod
130-
def __create__(self, data: Any) -> 'BuildComponent':
128+
def __create__(self, data: dict) -> 'BuildComponent':
131129
return BuildComponent(data)
132130

133131

134132
class BuildComponent(Component):
135-
def __init__(self, data: Any):
133+
def __init__(self, data: dict) -> None:
136134
super().__init__(data)
137135
self.repository = data["repository"]
138136
self.ref = data["ref"]

src/manifests/bundle/bundle_manifest_1_0.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# this file be licensed under the Apache-2.0 license or a
55
# compatible open source license.
66

7-
from typing import Any
8-
97
from manifests.component_manifest import Component, ComponentManifest, Components
108

119

@@ -59,7 +57,7 @@ class BundleManifest_1_0(ComponentManifest['BundleManifest_1_0', 'BundleComponen
5957
},
6058
}
6159

62-
def __init__(self, data: Any):
60+
def __init__(self, data: dict) -> None:
6361
super().__init__(data)
6462
self.build = self.Build(data["build"])
6563
self.components = BundleComponents_1_0(data.get("components", [])) # type: ignore[assignment]
@@ -72,7 +70,7 @@ def __to_dict__(self) -> dict:
7270
}
7371

7472
class Build:
75-
def __init__(self, data: Any):
73+
def __init__(self, data: dict) -> None:
7674
self.name = data["name"]
7775
self.version = data["version"]
7876
self.architecture = data["architecture"]
@@ -91,12 +89,12 @@ def __to_dict__(self) -> dict:
9189

9290
class BundleComponents_1_0(Components):
9391
@classmethod
94-
def __create__(self, data: Any) -> 'BundleComponent_1_0':
92+
def __create__(self, data: dict) -> 'BundleComponent_1_0':
9593
return BundleComponent_1_0(data)
9694

9795

9896
class BundleComponent_1_0(Component):
99-
def __init__(self, data: Any):
97+
def __init__(self, data: dict) -> None:
10098
super().__init__(data)
10199
self.repository = data["repository"]
102100
self.ref = data["ref"]

src/manifests/bundle_manifest.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# this file be licensed under the Apache-2.0 license or a
55
# compatible open source license.
66

7-
from typing import Any, Dict
7+
from typing import Dict
88

99
from manifests.bundle.bundle_manifest_1_0 import BundleManifest_1_0
1010
from manifests.component_manifest import Component, ComponentManifest, Components
@@ -65,7 +65,7 @@ class BundleManifest(ComponentManifest['BundleManifest', 'BundleComponents']):
6565
},
6666
}
6767

68-
def __init__(self, data: Any) -> None:
68+
def __init__(self, data: dict) -> None:
6969
super().__init__(data)
7070
self.build = self.Build(data["build"])
7171
self.components = BundleComponents(data.get("components", [])) # type: ignore[assignment]
@@ -78,7 +78,7 @@ def __to_dict__(self) -> dict:
7878
}
7979

8080
class Build:
81-
def __init__(self, data: Dict[str, str]):
81+
def __init__(self, data: Dict[str, str]) -> None:
8282
self.name = data["name"]
8383
self.version = data["version"]
8484
self.platform = data["platform"]
@@ -105,12 +105,12 @@ def filename(self) -> str:
105105

106106
class BundleComponents(Components['BundleComponent']):
107107
@classmethod
108-
def __create__(self, data: Any) -> 'BundleComponent':
108+
def __create__(self, data: dict) -> 'BundleComponent':
109109
return BundleComponent(data)
110110

111111

112112
class BundleComponent(Component):
113-
def __init__(self, data: Any):
113+
def __init__(self, data: dict) -> None:
114114
super().__init__(data)
115115
self.repository = data["repository"]
116116
self.ref = data["ref"]

src/manifests/component_manifest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ComponentManifest(Manifest[ManifestType], Generic[ManifestType, Components
2626
}
2727
}
2828

29-
def __init__(self, data: Any) -> None:
29+
def __init__(self, data: dict) -> None:
3030
super().__init__(data)
3131

3232
self.components = Components(data.get("components", [])) # type: ignore[assignment]
@@ -44,7 +44,7 @@ def __init__(self, data: Dict[Any, Any]) -> None:
4444
super().__init__(map(create_component, data))
4545

4646
@classmethod
47-
def __create__(self, data: Any) -> ComponentType:
47+
def __create__(self, data: dict) -> ComponentType:
4848
return Component(data) # type: ignore[return-value]
4949

5050
def __to_dict__(self) -> List[Dict[Any, Any]]:

src/manifests/distribution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class DistributionNotFound(Exception):
7-
def __init__(self, urls: List[str]):
7+
def __init__(self, urls: List[str]) -> None:
88
self.urls = urls
99
super().__init__(f"Unable to find a distribution under urls {self.urls}")
1010

src/manifests/input_manifest.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import copy
4040
import itertools
4141
import logging
42-
from typing import Any, Callable, Iterator, List, Optional
42+
from typing import Callable, Iterator, List, Optional
4343

4444
from git.git_repository import GitRepository
4545
from manifests.component_manifest import Component, ComponentManifest, Components
@@ -101,7 +101,7 @@ class InputManifest(ComponentManifest['InputManifest', 'InputComponents']):
101101
},
102102
}
103103

104-
def __init__(self, data: Any):
104+
def __init__(self, data: dict) -> None:
105105
super().__init__(data)
106106

107107
self.build = self.Build(data["build"])
@@ -123,14 +123,14 @@ def stable(self) -> 'InputManifest':
123123
return manifest
124124

125125
class Ci:
126-
def __init__(self, data: Any):
126+
def __init__(self, data: dict) -> None:
127127
self.image = None if data is None else self.Image(data.get("image", None))
128128

129129
def __to_dict__(self) -> Optional[dict]:
130130
return None if self.image is None else {"image": self.image.__to_dict__()}
131131

132132
class Image:
133-
def __init__(self, data: Any):
133+
def __init__(self, data: dict) -> None:
134134
self.name = data["name"]
135135
self.args = data.get("args", None)
136136

@@ -141,7 +141,7 @@ def __to_dict__(self) -> dict:
141141
}
142142

143143
class Build:
144-
def __init__(self, data: Any):
144+
def __init__(self, data: dict) -> None:
145145
self.name: str = data["name"]
146146
self.version = data["version"]
147147
self.qualifier = data.get("qualifier", None)
@@ -168,7 +168,7 @@ def filename(self) -> str:
168168

169169
class InputComponents(Components['InputComponent']):
170170
@classmethod
171-
def __create__(self, data: Any) -> 'InputComponent':
171+
def __create__(self, data: dict) -> 'InputComponent':
172172
return InputComponent._from(data) # type: ignore[no-any-return]
173173

174174
def __stabilize__(self) -> None:
@@ -199,13 +199,13 @@ def select(self, focus: List[str] = [], platform: str = None) -> Iterator['Input
199199

200200

201201
class InputComponent(Component):
202-
def __init__(self, data: Any):
202+
def __init__(self, data: dict) -> None:
203203
super().__init__(data)
204204
self.platforms = data.get("platforms", None)
205205
self.checks = list(map(lambda entry: Check(entry), data.get("checks", [])))
206206

207207
@classmethod
208-
def _from(self, data: Any) -> 'InputComponent':
208+
def _from(self, data: dict) -> 'InputComponent':
209209
if "repository" in data:
210210
return InputComponentFromSource(data)
211211
elif "dist" in data:
@@ -232,7 +232,7 @@ def __stabilize__(self) -> None:
232232

233233

234234
class InputComponentFromSource(InputComponent):
235-
def __init__(self, data: Any) -> None:
235+
def __init__(self, data: dict) -> None:
236236
super().__init__(data)
237237
self.repository = data["repository"]
238238
self.ref = data["ref"]
@@ -255,7 +255,7 @@ def __to_dict__(self) -> dict:
255255

256256

257257
class InputComponentFromDist(InputComponent):
258-
def __init__(self, data: Any):
258+
def __init__(self, data: dict) -> None:
259259
super().__init__(data)
260260
self.dist = data["dist"]
261261

@@ -269,7 +269,7 @@ def __to_dict__(self) -> dict:
269269

270270

271271
class Check:
272-
def __init__(self, data: Any) -> None:
272+
def __init__(self, data: dict) -> None:
273273
if isinstance(data, dict):
274274
if len(data) != 1:
275275
raise ValueError(f"Invalid check format: {data}")

0 commit comments

Comments
 (0)