Skip to content

Commit be12a83

Browse files
tooling: Reduce most of Pylance remaning new types of warnings (#931)
Fix most of the Pylance warnings for reportUnknownVariableType except those related to the Metamodel complex data type.
1 parent be0241c commit be12a83

11 files changed

Lines changed: 292 additions & 223 deletions

File tree

tooling/docs/_tooling/extensions/score_draw_uml_funcs/__init__.py

Lines changed: 120 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ def draw_comp_incl_impl_int(
9696
9797
:param dict[str,str] need: Component which should be drawn
9898
:param dict all_needs: Dictionary containing all needs
99-
:param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented interfaces
100-
which were already processed during this cycle
101-
:param dict[str,dict] proc_used_interfaces: Dictionary containing all used interfaces
102-
which were already processed during this cycle
99+
:param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented
100+
interfaces which were already processed during this cycle
101+
:param dict[str,dict] proc_used_interfaces: Dictionary containing
102+
all used interfaces which were already processed during this cycle
103103
"""
104104
# Draw outer component
105105
structure_text = f"{gen_struct_element('component', need)} {{\n"
@@ -229,94 +229,123 @@ def draw_module(
229229
proc_used_interfaces: dict[str, list[str]] = dict()
230230
proc_logical_interfaces: dict[str, str] = dict()
231231

232+
structure_text = f"{gen_struct_element('package', need)} {{\n"
232233
linkage_text = ""
233234

234-
# Draw outer module
235-
structure_text = f"{gen_struct_element('package', need)} {{\n"
235+
structure_text, linkage_text, proc_impl_interfaces, proc_used_interfaces = (
236+
process_included_components(
237+
need,
238+
all_needs,
239+
structure_text,
240+
linkage_text,
241+
proc_impl_interfaces,
242+
proc_used_interfaces,
243+
)
244+
)
245+
structure_text += f"}} /' {need['title']} '/ \n\n"
246+
247+
structure_text, linkage_text, proc_logical_interfaces = add_logical_interfaces(
248+
proc_impl_interfaces,
249+
proc_logical_interfaces,
250+
all_needs,
251+
structure_text,
252+
linkage_text,
253+
)
254+
structure_text, linkage_text = add_used_interfaces(
255+
proc_used_interfaces,
256+
proc_impl_interfaces,
257+
all_needs,
258+
structure_text,
259+
linkage_text,
260+
)
261+
linkage_text = "\n".join(set(linkage_text.split("\n"))) + "\n"
236262

237-
# Draw inner components recursively
263+
return structure_text, linkage_text
264+
265+
266+
def process_included_components(
267+
need: dict[str, str],
268+
all_needs: dict[str, dict[str, str]],
269+
structure_text: str,
270+
linkage_text: str,
271+
proc_impl_interfaces: dict[str, str],
272+
proc_used_interfaces: dict[str, list[str]],
273+
) -> tuple[str, str, dict[str, str], dict[str, list[str]]]:
238274
for need_inc in need.get("includes", []):
239275
curr_need = all_needs.get(need_inc, {})
240-
241-
# check for misspelled include
242276
if not curr_need:
243277
logger.info(f"{need}: include with id {need_inc} could not be found")
244278
continue
245-
246279
if curr_need["type"] not in ["comp_arc_sta", "mod_view_sta"]:
247280
continue
248-
249281
sub_structure, sub_linkage, proc_impl_interfaces, proc_used_interfaces = (
250282
draw_comp_incl_impl_int(
251-
curr_need, all_needs, proc_impl_interfaces, proc_used_interfaces
283+
curr_need,
284+
all_needs,
285+
proc_impl_interfaces,
286+
proc_used_interfaces,
252287
)
253288
)
254-
255289
structure_text += sub_structure
256290
linkage_text += sub_linkage
257291

258-
# close outer component
259-
structure_text += f"}} /' {need['title']} '/ \n\n"
292+
return structure_text, linkage_text, proc_impl_interfaces, proc_used_interfaces
293+
260294

261-
# Add logical interfaces only to implemented interfaces
295+
def add_logical_interfaces(
296+
proc_impl_interfaces: dict[str, str],
297+
proc_logical_interfaces: dict[str, str],
298+
all_needs: dict[str, dict[str, str]],
299+
structure_text: str,
300+
linkage_text: str,
301+
) -> tuple[str, str, dict[str, str]]:
262302
for iface in proc_impl_interfaces:
263-
if not (proc_logical_interfaces.get(iface, [])):
264-
# Currently only one Logical Interface per Real Interface supported
303+
if not proc_logical_interfaces.get(iface, []):
265304
logical_iface_tmp = get_logical_interface_real(iface, all_needs)
266305
if len(logical_iface_tmp) > 1:
267306
logger.warning(
268-
f"{logical_iface_tmp}: only one logical interface per real interface supported"
307+
f"{logical_iface_tmp}: only one logical interface per real "
308+
"interface supported"
269309
)
270310
if logical_iface_tmp:
271311
logical_iface = logical_iface_tmp[0]
272312
proc_logical_interfaces[logical_iface] = iface
273-
274313
structure_text += gen_interface_element(logical_iface, all_needs, True)
275-
276-
linkage_text += f"{
277-
gen_link_text(
278-
all_needs[iface],
279-
'-u->',
280-
all_needs[logical_iface],
281-
'implements',
282-
)
283-
} \n"
314+
linkage_text += f"{gen_link_text(all_needs[iface], '-u->',
315+
all_needs[logical_iface],
316+
'implements')}\n"
284317
else:
285318
print(f"{iface}: Not connected to any virtual interface")
319+
return structure_text, linkage_text, proc_logical_interfaces
286320

287-
# Add all interfaces which are used by component
321+
322+
def add_used_interfaces(
323+
proc_used_interfaces: dict[str, list[str]],
324+
proc_impl_interfaces: dict[str, str],
325+
all_needs: dict[str, dict[str, str]],
326+
structure_text: str,
327+
linkage_text: str,
328+
) -> tuple[str, str]:
288329
for iface, comps in proc_used_interfaces.items():
289330
if iface not in proc_impl_interfaces:
290-
# Add implementing components and modules
291331
impl_comp_str = get_impl_comp_from_real_iface(iface, all_needs)
292-
293332
impl_comp = all_needs.get(impl_comp_str[0], {}) if impl_comp_str else ""
294333

295334
if impl_comp:
296335
retval = get_hierarchy_text(impl_comp_str[0], all_needs)
297-
structure_text += retval[2] # module open
298-
structure_text += retval[0] # rest open
299-
300-
structure_text += retval[1] # rest close
301-
structure_text += retval[3] # module close
336+
structure_text += retval[2] + retval[0] + retval[1] + retval[3]
302337
structure_text += gen_interface_element(iface, all_needs, True)
303-
304-
# Draw connection between implementing components and interface
305-
linkage_text += f"{gen_link_text(impl_comp, '-u->', all_needs[iface], 'implements')} \n"
306-
338+
linkage_text += f"{gen_link_text(impl_comp, '-u->',
339+
all_needs[iface],
340+
'implements')} \n"
307341
else:
308-
# Add only interface if component not defined
309342
print(f"{iface}: No implementing component defined")
310343
structure_text += gen_interface_element(iface, all_needs, True)
311344

312-
# Interface can be used by multiple components
313345
for comp in comps:
314-
# Draw connection between used interfaces and components
315-
linkage_text += f"{gen_link_text(all_needs[comp], '-d[#green]->', all_needs[iface], 'uses')} \n"
316-
317-
# Remove duplicate links
318-
linkage_text = "\n".join(set(linkage_text.split("\n"))) + "\n"
319-
346+
linkage_text += f"{gen_link_text(all_needs[comp],
347+
'-d[#green]->',
348+
all_needs[iface], 'uses')} \n"
320349
return structure_text, linkage_text
321350

322351

@@ -332,77 +361,68 @@ def __repr__(self):
332361
def __call__(
333362
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
334363
) -> str:
335-
interfacelist: list[str] = []
336-
impl_comp: dict[str, str] = dict()
337-
338-
structure_text = (
339-
f'actor "Feature User" as {get_alias({"id": "Feature_User"})} \n'
364+
interfacelist = self._get_interface_list(need, all_needs)
365+
structure_text, impl_comp = self._generate_structure_and_components(
366+
interfacelist, all_needs
340367
)
368+
link_text = self._generate_links(interfacelist, impl_comp, all_needs, need)
369+
return gen_header() + structure_text + link_text
341370

342-
# Define Feature as a package
343-
# structure_text += f"{gen_struct_element('package', need)} {{\n"
344-
345-
# Add logical Interfaces / Interface Operations (aka includes)
371+
def _get_interface_list(
372+
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
373+
) -> list[str]:
374+
interfacelist: list[str] = []
346375
for need_inc in need.get("includes", []):
347-
# Generate list of interfaces since both interfaces
348-
# and interface operations can be included
349376
iface = get_interface_from_int(need_inc, all_needs)
350377
if iface not in interfacelist:
351378
interfacelist.append(iface)
379+
return interfacelist
380+
381+
def _generate_structure_and_components(
382+
self,
383+
interfacelist: list[str],
384+
all_needs: dict[str, dict[str, str]],
385+
) -> tuple[str, dict[str, str]]:
386+
structure_text = (
387+
f'actor "Feature User" as {get_alias({"id": "Feature_User"})} \n'
388+
)
389+
impl_comp: dict[str, str] = {}
352390

353391
for iface in interfacelist:
354-
if imcomp := all_needs.get(iface):
392+
if all_needs.get(iface):
355393
structure_text += gen_interface_element(iface, all_needs, True)
356-
357-
# Determine Components which implement the interfaces
358394
real_iface = get_real_interface_logical(iface, all_needs)
359395
if real_iface:
360396
comps = get_impl_comp_from_real_iface(real_iface[0], all_needs)
361-
362397
if comps:
363398
impl_comp[iface] = comps[0]
364-
365-
if imcomp := impl_comp.get(iface, {}):
366-
structure_text += (
367-
f"{gen_struct_element('component', all_needs[imcomp])}\n"
368-
)
399+
if im := impl_comp.get(iface):
400+
structure_text += f"{gen_struct_element('component',
401+
all_needs[im])}\n"
369402
else:
370-
logger.info(f"{need}: Interface {iface} could not be found")
371-
continue
372-
373-
# Close Package
374-
# structure_text += f"}} /' {need['title']} '/ \n\n"
375-
403+
logger.info(f"Interface {iface} could not be found")
404+
return structure_text, impl_comp
405+
406+
def _generate_links(
407+
self,
408+
interfacelist: list[str],
409+
impl_comp: dict[str, str],
410+
all_needs: dict[str, dict[str, str]],
411+
need: dict[str, str],
412+
) -> str:
376413
link_text = ""
377-
378414
for iface in interfacelist:
379415
if imcomp := impl_comp.get(iface):
380-
# Add relation between Actor and Interfaces
381-
link_text += f"{
382-
gen_link_text(
383-
{'id': 'Feature_User'}, '-d->', all_needs[iface], 'use'
384-
)
385-
} \n"
386-
387-
# Add relation between interface and component
388-
if imcomp := impl_comp.get(iface):
389-
link_text += f"{
390-
gen_link_text(
391-
all_needs[imcomp],
392-
'-u->',
393-
all_needs[iface],
394-
'implements',
395-
)
396-
} \n"
397-
else:
398-
logger.info(
399-
f"Interface {iface} is not implemented by any component"
400-
)
416+
link_text += f"{gen_link_text({'id': 'Feature_User'}, '-d->',
417+
all_needs[iface],
418+
'use')} \n"
419+
link_text += f"{gen_link_text(all_needs[imcomp],
420+
'-u->',
421+
all_needs[iface],
422+
'implements')} \n"
401423
else:
402424
logger.info(f"{need}: Interface {iface} could not be found")
403-
continue
404-
405-
return gen_header() + structure_text + link_text
425+
return link_text
406426

407427

408428
class draw_full_module:

tooling/docs/_tooling/extensions/score_draw_uml_funcs/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ def get_impl_comp_from_real_iface(
276276
real_iface: str, all_needs: dict[str, dict[str, str]]
277277
) -> list[str]:
278278
"""Get implementing component of the interface"""
279-
implcomp: list[str] = all_needs[real_iface].get("implements_back", [])
280-
279+
value = all_needs[real_iface].get("implements_back", [])
280+
implcomp = value if isinstance(value, list) else []
281281
if not implcomp:
282282
logger.info(
283283
f"{all_needs[real_iface]['id']}: Implementing Component not specified!"

tooling/docs/_tooling/extensions/score_header_service/header_service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import re
1717
import subprocess
1818
from collections import defaultdict
19-
from typing import Any, ClassVar
19+
from typing import Any
2020

2121
from github import (
2222
Auth,
@@ -72,7 +72,7 @@ def generate_hash() -> str:
7272

7373

7474
class HeaderService(BaseService):
75-
options = {}
75+
options = []
7676

7777
def __init__(
7878
self,
@@ -141,7 +141,10 @@ def _extract_merge_commit_data(location: str) -> dict[str, str | list[str]]:
141141
"hash": "N/A",
142142
}
143143

144-
git_cmd = f'git log --pretty="format:%H%n%an, %ae%n%b" --max-count=1 --merges --first-parent -p "{location}'
144+
git_cmd = (
145+
f'git log --pretty="format:%H%n%an, %ae%n%b" --max-count=1 --merges '
146+
f'--first-parent -p "{location}"'
147+
)
145148

146149
result = subprocess.run([git_cmd], shell=True, capture_output=True)
147150

tooling/docs/_tooling/extensions/score_header_service/test/test_header_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import pytest
1818
import score_header_service.header_service as hs
19+
from sphinx.util.docutils import SphinxDirective
1920

2021

2122
@pytest.fixture(scope="session", autouse=True)
@@ -125,7 +126,8 @@ def test_debug(mock_app: MagicMock, mock_request_from_directive: MagicMock):
125126
debug_data = [{"key": "value"}]
126127
mock_request_from_directive.return_value = debug_data
127128
header_service = hs.HeaderService(mock_app, "dummy-service", None)
128-
assert header_service.debug(None) == debug_data
129+
mock_directive = MagicMock(spec=SphinxDirective) # ✅ This matches expected type
130+
assert header_service.debug(mock_directive) == debug_data
129131

130132

131133
@patch("score_header_service.header_service.subprocess.run")
@@ -156,7 +158,8 @@ def test_extract_merge_commit_data(run_mock: MagicMock):
156158
}
157159
run_mock.assert_called_once_with(
158160
[
159-
'git log --pretty="format:%H%n%an, %ae%n%b" --max-count=1 --merges --first-parent -p "/req/feature1'
161+
'git log --pretty="format:%H%n%an, %ae%n%b" '
162+
'--max-count=1 --merges --first-parent -p "/req/feature1"'
160163
],
161164
shell=True,
162165
capture_output=True,

tooling/docs/_tooling/extensions/score_layout/sphinx_options.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
needs_layouts = {
13+
from typing import Literal, TypedDict
14+
15+
LayoutDict = dict[str, list[str]]
16+
17+
18+
class SingleLayout(TypedDict):
19+
grid: Literal["complex", "content"]
20+
layout: dict[str, list[str]]
21+
22+
23+
needs_layouts: dict[str, SingleLayout] = {
1424
"score": {
1525
"grid": "complex",
1626
"layout": {

0 commit comments

Comments
 (0)