Skip to content

Commit 82dc32a

Browse files
tooling: Reduce 2 types of Pylance new warnings and more (#873)
Fix pylance warnings for reportMissingTypeArgument and reportUnusedVariable and some other warnings.
1 parent f58356a commit 82dc32a

File tree

11 files changed

+82
-51
lines changed

11 files changed

+82
-51
lines changed

Diff for: docs/_tooling/extensions/score_draw_uml_funcs/__init__.py

+26-15
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import time
3030
from functools import cache
3131
from pathlib import Path
32+
from typing import Any, Callable
3233

3334
from sphinx.application import Sphinx
3435
from sphinx_needs.logging import get_logger
@@ -50,7 +51,7 @@
5051
logger = get_logger(__file__)
5152

5253

53-
def setup(app: Sphinx) -> dict:
54+
def setup(app: Sphinx) -> dict[str, object]:
5455
app.config.needs_render_context = draw_uml_function_context
5556
return {
5657
"version": "0.1",
@@ -85,10 +86,10 @@ def scripts_directory_hash():
8586

8687
def draw_comp_incl_impl_int(
8788
need: dict[str, str],
88-
all_needs: dict[str, dict],
89+
all_needs: dict[str, dict[str, Any]],
8990
proc_impl_interfaces: dict[str, str],
90-
proc_used_interfaces: dict[str, list],
91-
) -> tuple[str, str, dict[str, str], dict[str, list]]:
91+
proc_used_interfaces: dict[str, list[str]],
92+
) -> tuple[str, str, dict[str, str], dict[str, list[str]]]:
9293
# Draw outer component
9394
structure_text = f"{gen_struct_element('component', need)} {{\n"
9495
linkage_text = ""
@@ -129,7 +130,7 @@ def draw_comp_incl_impl_int(
129130
logger.info(f"{need}: implements {iface} could not be found")
130131
continue
131132

132-
if not (interface := proc_impl_interfaces.get(iface, [])):
133+
if not proc_impl_interfaces.get(iface, []):
133134
structure_text += gen_interface_element(iface, all_needs, True)
134135
linkage_text += f"{
135136
gen_link_text(
@@ -148,7 +149,7 @@ def draw_comp_incl_impl_int(
148149
logger.info(f"{need}: uses {iface} could not be found")
149150
continue
150151

151-
if not (interface := proc_used_interfaces.get(iface, [])):
152+
if not proc_used_interfaces.get(iface, []):
152153
proc_used_interfaces[iface] = [need["id"]]
153154
else:
154155
proc_used_interfaces[iface].append(need["id"])
@@ -158,7 +159,7 @@ def draw_comp_incl_impl_int(
158159

159160
def draw_module(
160161
need: dict[str, str],
161-
all_needs: dict[str, dict],
162+
all_needs: dict[str, dict[str, Any]],
162163
) -> tuple[str, str]:
163164
"""
164165
Drawing and parsing function of a component.
@@ -247,7 +248,7 @@ def draw_module(
247248
structure_text += f"}} /' {need['title']} '/ \n\n"
248249

249250
# Add logical interfaces only to implemented interfaces
250-
for iface, component in proc_impl_interfaces.items():
251+
for iface in proc_impl_interfaces:
251252
if not (proc_logical_interfaces.get(iface, [])):
252253
# Currently only one Logical Interface per Real Interface supported
253254
logical_iface_tmp = get_logical_interface_real(iface, all_needs)
@@ -316,7 +317,9 @@ class draw_full_feature:
316317
def __repr__(self):
317318
return "draw_full_feature" + " in " + scripts_directory_hash()
318319

319-
def __call__(self, need, all_needs: dict) -> str:
320+
def __call__(
321+
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
322+
) -> str:
320323
interfacelist = []
321324
impl_comp = dict()
322325

@@ -382,7 +385,9 @@ class draw_full_module:
382385
def __repr__(self):
383386
return "draw_full_module" + " in " + scripts_directory_hash()
384387

385-
def __call__(self, need, all_needs) -> str:
388+
def __call__(
389+
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
390+
) -> str:
386391
structure_text, linkage_text = draw_module(need, all_needs)
387392

388393
return gen_header() + structure_text + linkage_text
@@ -392,9 +397,11 @@ class draw_full_component:
392397
def __repr__(self):
393398
return "draw_full_component" + " in " + scripts_directory_hash()
394399

395-
def __call__(self, need, all_needs) -> str:
396-
structure_text, linkage_text, processed_interfaces, logical_interfacelist = (
397-
draw_comp_incl_impl_int(need, all_needs, dict(), dict())
400+
def __call__(
401+
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
402+
) -> str:
403+
structure_text, linkage_text, _, _ = draw_comp_incl_impl_int(
404+
need, all_needs, dict(), dict()
398405
)
399406

400407
return gen_header() + structure_text + linkage_text
@@ -404,13 +411,17 @@ class draw_full_interface:
404411
def __repr__(self):
405412
return "draw_full_interface" + " in " + scripts_directory_hash()
406413

407-
def __call__(self, need, all_needs) -> str:
414+
def __call__(
415+
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
416+
) -> str:
408417
structure_text = gen_interface_element(need["id"], all_needs, True)
409418

410419
return structure_text + "\n"
411420

412421

413-
draw_uml_function_context = {
422+
CallableType = Callable[[dict[str, Any], dict[str, dict[str, Any]]], str]
423+
424+
draw_uml_function_context: dict[str, CallableType] = {
414425
"draw_interface": draw_full_interface(),
415426
"draw_module": draw_full_module(),
416427
"draw_component": draw_full_component(),

Diff for: docs/_tooling/extensions/score_draw_uml_funcs/helpers.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13+
from typing import Any
14+
15+
1316
def gen_need_link(need: dict[str, str]) -> str:
1417
"""Generate the link to the need element from the PlantUML Diagram"""
1518
link = ".." + "/" + need["docname"] + ".html#" + need["id_parent"]
@@ -69,7 +72,7 @@ def gen_struct_element(UMLelement: str, need: dict[str, str]) -> str:
6972

7073

7174
def gen_interface_element(
72-
need_id: str, all_needs: dict[str, dict], incl_ops: bool = False
75+
need_id: str, all_needs: dict[str, dict[str, Any]], incl_ops: bool = False
7376
) -> str:
7477
"""Generate interface text and include all operations if selected."""
7578

@@ -108,7 +111,9 @@ def gen_link_text(
108111
return f"{gen_alias(from_need)} {link_type} {gen_alias(to_need)}: {link_text}"
109112

110113

111-
def get_module(component: str, all_needs: dict[str, dict]) -> tuple[str, str, str, str]:
114+
def get_module(
115+
component: str, all_needs: dict[str, dict[str, Any]]
116+
) -> tuple[str, str, str, str]:
112117
need = all_needs[component]
113118

114119
open_text = ""
@@ -147,7 +152,7 @@ def get_module(component: str, all_needs: dict[str, dict]) -> tuple[str, str, st
147152

148153

149154
def get_interface_from_component(
150-
component: dict[str, str], relation: str, all_needs: dict[str, dict]
155+
component: dict[str, str], relation: str, all_needs: dict[str, dict[str, Any]]
151156
) -> list[str]:
152157
local_interfaces = []
153158

@@ -159,7 +164,7 @@ def get_interface_from_component(
159164
return local_interfaces
160165

161166

162-
def get_interface_from_int(need_id: str, all_needs: dict[str, dict]) -> str:
167+
def get_interface_from_int(need_id: str, all_needs: dict[str, dict[str, Any]]) -> str:
163168
"""Get Interface for a provided Interface or Interface Operation"""
164169
if "_int_op" in all_needs[need_id]["type"]:
165170
iface = all_needs[need_id]["included_by"][0]
@@ -169,7 +174,9 @@ def get_interface_from_int(need_id: str, all_needs: dict[str, dict]) -> str:
169174
return iface
170175

171176

172-
def get_real_interface_logical(logical_interface_id: str, all_needs: dict) -> list[str]:
177+
def get_real_interface_logical(
178+
logical_interface_id: str, all_needs: dict[str, dict[str, Any]]
179+
) -> list[str]:
173180
"""Get real interface for provided logical interface
174181
The relation is traced via the interface operations
175182
"""
@@ -188,7 +195,7 @@ def get_real_interface_logical(logical_interface_id: str, all_needs: dict) -> li
188195

189196

190197
def get_logical_interface_real(
191-
real_interface_id: str, all_needs: dict[str, dict]
198+
real_interface_id: str, all_needs: dict[str, dict[str, Any]]
192199
) -> list[str]:
193200
"""Get logical interface based on real interface"""
194201
logical_ifaces = list()
@@ -214,7 +221,9 @@ def get_logical_interface_real(
214221
return logical_ifaces
215222

216223

217-
def get_impl_comp_from_real_iface(real_iface: str, all_needs: dict[str, dict]) -> str:
224+
def get_impl_comp_from_real_iface(
225+
real_iface: str, all_needs: dict[str, dict[str, Any]]
226+
) -> str:
218227
"""Get implementing component of the interface"""
219228

220229
implcomp = all_needs[real_iface].get("implements_back", [])
@@ -228,7 +237,7 @@ def get_impl_comp_from_real_iface(real_iface: str, all_needs: dict[str, dict]) -
228237

229238

230239
def get_use_comp_from_real_iface(
231-
real_iface: str, all_needs: dict[str, dict]
240+
real_iface: str, all_needs: dict[str, dict[str, Any]]
232241
) -> list[str]:
233242
"""Get components which use the interface"""
234243
usecomp = all_needs[real_iface].get("uses_back", [])

Diff for: docs/_tooling/extensions/score_header_service/header_service.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
from collections import defaultdict
13+
import hashlib
1414
import os
15+
import random
1516
import re
1617
import subprocess
17-
import hashlib
18-
import random
18+
from collections import defaultdict
1919
from typing import Any
2020

2121
from github import (
@@ -26,11 +26,11 @@
2626
PullRequestReview,
2727
Repository,
2828
)
29-
from sphinx_needs.services.base import BaseService
30-
from sphinx.environment import BuildEnvironment
31-
from sphinx_needs.data import SphinxNeedsData
3229
from sphinx.application import Sphinx
30+
from sphinx.environment import BuildEnvironment
3331
from sphinx.util.docutils import SphinxDirective
32+
from sphinx_needs.data import SphinxNeedsData
33+
from sphinx_needs.services.base import BaseService
3434

3535
# req-traceability: GD__automatic_document_header_generation
3636
APPROVER_TEAMS = ["automotive-score-committers"]
@@ -155,7 +155,7 @@ def _extract_merge_commit_data(location: str) -> dict[str, str | list[str]]:
155155
hash = lines[0]
156156
author = lines[1]
157157

158-
data: defaultdict[str, list] = defaultdict(list)
158+
data: defaultdict[str, list[str]] = defaultdict(list)
159159

160160
pattern = r"(Approved|Reviewed): \{(.*)} \( \{(.*)\} \) on \{(.*)\}"
161161

Diff for: docs/_tooling/extensions/score_layout/html_options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sphinx.application import Sphinx
1414

1515

16-
def return_html_theme_options(app: Sphinx) -> dict:
16+
def return_html_theme_options(app: Sphinx) -> dict[str, object]:
1717
return {
1818
"navbar_align": "content",
1919
"header_links_before_dropdown": 5,

Diff for: docs/_tooling/extensions/score_metamodel/checks/standards.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
# from sphinx.application import Sphinx
14+
from typing import Any
15+
1416
from sphinx_needs.data import NeedsInfoType
1517

1618
# from score_metamodel import (
@@ -19,39 +21,41 @@
1921
# )
2022

2123

22-
def get_standards_needs(needs: list[NeedsInfoType]) -> dict:
24+
def get_standards_needs(needs: list[NeedsInfoType]) -> dict[str, NeedsInfoType]:
2325
"""
2426
Return a dictionary of all standard requirements from the Sphinx app's needs.
2527
"""
2628

2729
return {need["id"]: need for need in needs if need["type"] == "std_req"}
2830

2931

30-
def get_standards_workproducts(needs: list[NeedsInfoType]) -> dict:
32+
def get_standards_workproducts(
33+
needs: list[NeedsInfoType],
34+
) -> dict[str, NeedsInfoType]:
3135
"""
3236
Return a dictionary of standard workproducts from the Sphinx app's needs.
3337
"""
3438

3539
return {need["id"]: need for need in needs if need["type"] == "std_wp"}
3640

3741

38-
def get_workflows(needs: list[NeedsInfoType]) -> dict:
42+
def get_workflows(needs: list[NeedsInfoType]) -> dict[str, NeedsInfoType]:
3943
"""
4044
Return a dictionary of all workflows from the Sphinx app's needs.
4145
"""
4246

4347
return {need["id"]: need for need in needs if need.get("type") == "workflow"}
4448

4549

46-
def get_workproducts(needs: list[NeedsInfoType]) -> dict:
50+
def get_workproducts(needs: list[NeedsInfoType]) -> dict[str, NeedsInfoType]:
4751
"""
4852
Return a dictionary of all workproducts from the Sphinx app's needs.
4953
"""
5054

5155
return {need["id"]: need for need in needs if need.get("type") == "workproduct"}
5256

5357

54-
def get_compliance_req_needs(needs) -> set:
58+
def get_compliance_req_needs(needs: list[NeedsInfoType]) -> set[str]:
5559
"""
5660
Return a set of all compliance_req values from the Sphinx app's needs,
5761
but only if the need type is one of the specified process-related types.
@@ -65,7 +69,7 @@ def get_compliance_req_needs(needs) -> set:
6569
}
6670

6771

68-
def get_compliance_wp_needs(needs) -> set:
72+
def get_compliance_wp_needs(needs: list[NeedsInfoType]) -> set[str]:
6973
"""
7074
Return a set of all compliance_wp values from the Sphinx app's needs,
7175
but only if the need type is "workproduct".
@@ -104,7 +108,7 @@ def get_compliance_wp_needs(needs) -> set:
104108
#
105109
# @graph_check
106110
# def check_all_standard_workproducts_linked_item_via_the_compliance_wp(
107-
# app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger
111+
# app: Sphinx,needs: list[NeedsInfoType], log: CheckLogger
108112
# ):
109113
# """
110114
# Checks if all standard work products are linked to an item via the complies tag.
@@ -124,7 +128,7 @@ def get_compliance_wp_needs(needs) -> set:
124128
#
125129
# @graph_check
126130
# def check_workproduct_uniqueness_over_workflows(
127-
# app: Sphinx, needs: list[NeedsInfoType], log: CheckLogger
131+
# app: Sphinx,needs: list[NeedsInfoType], log: CheckLogger
128132
# ):
129133
# """
130134
# Check if all workproducts are contained in exactly one workflow.
@@ -141,7 +145,7 @@ def get_compliance_wp_needs(needs) -> set:
141145
#
142146
# # Iterate over workflows and update the counts and workflows
143147
# for workflow in all_workflows.values():
144-
# for output in workflow["output"]:
148+
# for output in workflow.get("output",[]):
145149
# # Increment count and add workflow_id if workproduct is in analysis
146150
# if output in workproduct_analysis:
147151
# workproduct_analysis[output]["count"] += 1
@@ -173,7 +177,9 @@ def get_compliance_wp_needs(needs) -> set:
173177
# ╰─────────────────────────────────────────────────────────────────────────────╯
174178

175179

176-
def my_pie_linked_standard_requirements(needs, results, **kwargs):
180+
def my_pie_linked_standard_requirements(
181+
needs: list[NeedsInfoType], results: list[int], **kwargs: str | int | float
182+
) -> None:
177183
"""
178184
Function to render the chart of check for standard requirements linked
179185
to at least an item via compliance-gd.
@@ -204,7 +210,9 @@ def my_pie_linked_standard_requirements(needs, results, **kwargs):
204210
results.append(cnt_not_connected)
205211

206212

207-
def my_pie_linked_standard_workproducts(needs, results, **kwargs):
213+
def my_pie_linked_standard_workproducts(
214+
needs: list[NeedsInfoType], results: list[int], **kwargs: str | int | float
215+
) -> None:
208216
"""
209217
Function to render the chart of check for standar workproducts linked
210218
to at least an item via compliance-wp.
@@ -236,7 +244,9 @@ def my_pie_linked_standard_workproducts(needs, results, **kwargs):
236244
results.append(cwp_not_connected)
237245

238246

239-
def my_pie_workproducts_contained_in_exactly_one_workflow(needs, results, **kwargs):
247+
def my_pie_workproducts_contained_in_exactly_one_workflow(
248+
needs: list[NeedsInfoType], results: list[int], **kwargs: str | int | float
249+
) -> None:
240250
"""
241251
Function to render the chart of check for workproducts that are contained
242252
in exactly one workflow, the not connected once and the once
@@ -250,7 +260,7 @@ def my_pie_workproducts_contained_in_exactly_one_workflow(needs, results, **kwar
250260

251261
# Iterate over workflows and update the counts and workflows
252262
for workflow in all_workflows.values():
253-
for output in workflow["output"]:
263+
for output in workflow.get("output", []):
254264
# Increment count and add workflow_id if workproduct is in analysis
255265
if output in workproduct_analysis:
256266
workproduct_analysis[output]["count"] += 1

0 commit comments

Comments
 (0)