Skip to content

Commit 61ddc1d

Browse files
committed
code-climate: address remaining var-annotated
1 parent a43e47f commit 61ddc1d

File tree

14 files changed

+64
-46
lines changed

14 files changed

+64
-46
lines changed

strictdoc/backend/excel/export/excel_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="arg-type,no-untyped-def,type-arg,union-attr,var-annotated"
1+
# mypy: disable-error-code="arg-type,no-untyped-def,type-arg,union-attr"
22
import os
33
from pathlib import Path
44
from typing import Dict, List
@@ -239,7 +239,7 @@ def _lookup_refs(document_contents: List) -> Dict[str, int]:
239239

240240
@staticmethod
241241
def _init_columns_width(fields: List[str]):
242-
columns = {}
242+
columns: Dict[str, Dict[str, int]] = {}
243243

244244
for field in fields:
245245
columns[field] = {}

strictdoc/backend/sdoc_source_code/models/source_file_info.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# mypy: disable-error-code="no-untyped-def,type-arg,var-annotated"
2-
from typing import Dict, List, Optional, Union
1+
# mypy: disable-error-code="no-untyped-def,type-arg"
2+
from typing import Dict, List, Optional, Sequence, Union
3+
4+
from typing_extensions import TypeAlias
35

46
from strictdoc.backend.sdoc_source_code.models.function import Function
57
from strictdoc.backend.sdoc_source_code.models.function_range_marker import (
@@ -14,6 +16,10 @@
1416
from strictdoc.helpers.auto_described import auto_described
1517
from strictdoc.helpers.file_stats import SourceFileStats
1618

19+
RelationMarkerType: TypeAlias = Union[
20+
FunctionRangeMarker, LineMarker, RangeMarker, ForwardRangeMarker
21+
]
22+
1723

1824
@auto_described
1925
class SourceFileTraceabilityInfo:
@@ -34,9 +40,13 @@ def __init__(self, g_parts: List):
3440
# "REQ-001": [RangeMarker(...), ...], # noqa: ERA001
3541
# "REQ-002": [RangeMarker(...), ...], # noqa: ERA001
3642
# } # noqa: ERA001
37-
self.ng_map_reqs_to_markers = {}
43+
self.ng_map_reqs_to_markers: Dict[
44+
str, Sequence[RelationMarkerType]
45+
] = {}
3846

39-
self.ng_map_names_to_markers: Dict[str, List] = {}
47+
self.ng_map_names_to_markers: Dict[
48+
str, Sequence[RelationMarkerType]
49+
] = {}
4050
self.ng_map_names_to_definition_functions: Dict[str, Function] = {}
4151

4252
#
@@ -53,11 +63,7 @@ def __init__(self, g_parts: List):
5363
self._coverage: float = 0
5464
self.covered_functions: int = 0
5565

56-
self.markers: List[
57-
Union[
58-
FunctionRangeMarker, LineMarker, RangeMarker, ForwardRangeMarker
59-
]
60-
] = []
66+
self.markers: List[RelationMarkerType] = []
6167

6268
def get_coverage(self):
6369
return self._coverage

strictdoc/backend/sdoc_source_code/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg,var-annotated"
1+
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg"
22
import sys
33
import traceback
44
from functools import partial

strictdoc/backend/sdoc_source_code/reader_c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg,var-annotated"
1+
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg"
22
import sys
33
import traceback
44
from typing import List, Optional, Sequence, Union

strictdoc/backend/sdoc_source_code/reader_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg,var-annotated"
1+
# mypy: disable-error-code="no-redef,no-untyped-call,no-untyped-def,type-arg"
22
import sys
33
import traceback
44
from itertools import islice

strictdoc/core/file_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="no-any-return,no-untyped-call,no-untyped-def,var-annotated"
1+
# mypy: disable-error-code="no-any-return,no-untyped-call,no-untyped-def"
22
import collections
33
import functools
44
import os
@@ -35,7 +35,7 @@ def __init__(self, level, full_path, rel_path: SDocRelativePath):
3535
self.rel_path: SDocRelativePath = rel_path
3636
self.file_name = os.path.basename(self.full_path)
3737
self.files = [self]
38-
self.subfolder_trees = []
38+
self.subfolder_trees: List[Folder] = []
3939

4040
def __repr__(self):
4141
return f"File: {self.full_path}"

strictdoc/core/project_config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="arg-type,attr-defined,no-any-return,no-untyped-call,no-untyped-def,var-annotated,type-arg"
1+
# mypy: disable-error-code="arg-type,attr-defined,no-any-return,no-untyped-call,no-untyped-def,type-arg"
22
import datetime
33
import os
44
import re
@@ -210,7 +210,7 @@ def default_config(environment: SDocRuntimeEnvironment):
210210
source_root_path=None,
211211
include_source_paths=[],
212212
exclude_source_paths=[],
213-
test_report_root_dict=[],
213+
test_report_root_dict={},
214214
html2pdf_template=None,
215215
bundle_document_version=ProjectConfig.DEFAULT_BUNDLE_DOCUMENT_VERSION,
216216
bundle_document_date=ProjectConfig.DEFAULT_BUNDLE_DOCUMENT_COMMIT_DATE,
@@ -424,12 +424,12 @@ def _load_from_dictionary(
424424
project_features = ProjectConfig.DEFAULT_FEATURES
425425
server_host = ProjectConfig.DEFAULT_SERVER_HOST
426426
server_port = ProjectConfig.DEFAULT_SERVER_PORT
427-
include_doc_paths = []
428-
exclude_doc_paths = []
427+
include_doc_paths: List[str] = []
428+
exclude_doc_paths: List[str] = []
429429
source_root_path = None
430-
include_source_paths = []
431-
exclude_source_paths = []
432-
test_report_root_dict = {}
430+
include_source_paths: List[str] = []
431+
exclude_source_paths: List[str] = []
432+
test_report_root_dict: Dict[str, str] = {}
433433
html2pdf_template: Optional[str] = None
434434
bundle_document_version = ProjectConfig.DEFAULT_BUNDLE_DOCUMENT_VERSION
435435
bundle_document_date = ProjectConfig.DEFAULT_BUNDLE_DOCUMENT_COMMIT_DATE

strictdoc/core/source_tree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="no-untyped-def,var-annotated"
1+
# mypy: disable-error-code="no-untyped-def"
22
import os
33
from enum import Enum
44
from typing import Dict, List, Sequence
@@ -21,7 +21,7 @@ class SourceFileType(Enum):
2121
RST = [".rst"]
2222
SDOC = [".sdoc"]
2323

24-
UNKNOWN = []
24+
UNKNOWN: List[str] = []
2525

2626
@classmethod
2727
def create_from_path(cls, path_to_file: str) -> "SourceFileType":
@@ -54,7 +54,7 @@ def create_from_path(cls, path_to_file: str) -> "SourceFileType":
5454

5555
@staticmethod
5656
def all() -> List[str]: # noqa: A003
57-
all_extensions = []
57+
all_extensions: List[str] = []
5858
for enum_value in SourceFileType:
5959
all_extensions += enum_value.value
6060
return all_extensions

strictdoc/core/tree_cycle_detector.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# mypy: disable-error-code="no-untyped-call,no-untyped-def,var-annotated"
1+
# mypy: disable-error-code="no-untyped-call,no-untyped-def"
22
from collections import deque
3+
from typing import Deque, Tuple
34

45
from strictdoc.backend.sdoc.errors.document_tree_error import DocumentTreeError
6+
from strictdoc.backend.sdoc.models.model import SDocNodeIF
57

68
BEFORE = 1
79
AFTER = 2
@@ -11,10 +13,10 @@ class TreeCycleDetector:
1113
def __init__(self):
1214
self.checked = set()
1315

14-
def check_node(self, node, links_function):
16+
def check_node(self, node: SDocNodeIF, links_function):
1517
if node in self.checked:
1618
return
17-
stack = deque()
19+
stack: Deque[Tuple[SDocNodeIF, int]] = deque()
1820
stack.append((node, BEFORE))
1921
visited = set()
2022
while stack:
@@ -46,7 +48,7 @@ class SingleShotTreeCycleDetector:
4648
def check_node(self, new_uid, node, links_function):
4749
checked = set()
4850

49-
stack = deque()
51+
stack: Deque[Tuple[SDocNodeIF, int]] = deque()
5052
stack.append((node, BEFORE))
5153
visited = {new_uid}
5254
while stack:

strictdoc/export/html/renderers/link_renderer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# mypy: disable-error-code="arg-type,no-untyped-call,no-untyped-def,union-attr,var-annotated"
1+
# mypy: disable-error-code="arg-type,no-untyped-call,no-untyped-def,union-attr"
22
import html
3-
from typing import Optional, Union
3+
from typing import Dict, Optional, Tuple, Union
44

55
from strictdoc.backend.sdoc.models.anchor import Anchor
66
from strictdoc.backend.sdoc.models.document import SDocDocument
@@ -24,8 +24,11 @@ def __init__(self, *, root_path, static_path: str):
2424
if len(root_path) > 0
2525
else f"{static_path}"
2626
)
27-
self.local_anchor_cache = {}
28-
self.req_link_cache = {}
27+
self.local_anchor_cache: Dict[str, str] = {}
28+
self.req_link_cache: Dict[
29+
Tuple[DocumentType, int],
30+
Dict[Union[SDocDocument, SDocNode, SDocSection, Anchor], str],
31+
] = {}
2932

3033
def render_url(self, url: str) -> str:
3134
url = html.escape(url)
@@ -165,7 +168,7 @@ def render_requirement_link_from_source_file(self, node, source_file):
165168
assert isinstance(node, SDocNode)
166169
assert isinstance(source_file, SourceFile)
167170
local_link = self.render_local_anchor(node)
168-
link_cache_key = ("document", source_file.level)
171+
link_cache_key = (DocumentType.document(), source_file.level)
169172
if link_cache_key in self.req_link_cache:
170173
document_type_cache = self.req_link_cache[link_cache_key]
171174
if node in document_type_cache:

strictdoc/export/json/json_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mypy: disable-error-code="arg-type,attr-defined,no-any-return,no-untyped-def,type-arg,var-annotated,union-attr,operator"
1+
# mypy: disable-error-code="arg-type,attr-defined,no-any-return,no-untyped-def,type-arg,union-attr,operator"
22
import json
33
import os.path
44
from enum import Enum
@@ -219,7 +219,7 @@ def get_level_string_(node_) -> str:
219219
return subnode_dict
220220

221221
elif isinstance(node, SDocDocument):
222-
node_dict = {JSONKey.NODES: []}
222+
node_dict: Dict[str, List[Dict]] = {JSONKey.NODES: []}
223223

224224
current_number = 0
225225
for subnode_ in node.section_contents:

strictdoc/export/spdx/spdx_to_sdoc_converter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# mypy: disable-error-code="arg-type,no-untyped-call,no-untyped-def,var-annotated,union-attr"
2-
from typing import Union
1+
# mypy: disable-error-code="arg-type,no-untyped-call,no-untyped-def,union-attr"
2+
from typing import List, Union
33

44
from spdx_tools.spdx3.model import RelationshipType, SpdxDocument
55
from spdx_tools.spdx3.model.software import File, Package, Snippet
@@ -12,6 +12,7 @@
1212
)
1313
from strictdoc.backend.sdoc.models.node import (
1414
SDocNode,
15+
SDocNodeField,
1516
)
1617
from strictdoc.backend.sdoc.models.reference import (
1718
ChildReqReference,
@@ -243,7 +244,7 @@ def _convert_file(
243244
sdoc_document: SDocDocument,
244245
sdoc_parent: Union[SDocSection, SDocDocument],
245246
) -> SDocNode:
246-
fields = []
247+
fields: List[SDocNodeField] = []
247248
requirement = SDocNode(
248249
parent=sdoc_parent,
249250
node_type="SPDX_FILE",
@@ -295,7 +296,7 @@ def _convert_snippet(
295296
sdoc_parent: Union[SDocSection, SDocDocument],
296297
spdx_container: SPDXSDocContainer,
297298
) -> SDocNode:
298-
fields = []
299+
fields: List[SDocNodeField] = []
299300
requirement = SDocNode(
300301
parent=sdoc_parent,
301302
node_type="SPDX_SNIPPET",

strictdoc/helpers/form_data.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# mypy: disable-error-code="no-untyped-call,no-untyped-def,type-arg,union-attr,var-annotated"
1+
# mypy: disable-error-code="no-untyped-call,no-untyped-def,type-arg,union-attr"
22
import re
3-
from typing import List, Tuple, Union
3+
from typing import Dict, List, Tuple, Union
4+
5+
from typing_extensions import TypeAlias
6+
7+
FormDataDictType: TypeAlias = Union[
8+
Dict[str, "FormDataDictType"], List["FormDataDictType"]
9+
]
410

511

612
def _set_value_by_key_path(obj, parts, value):
@@ -51,8 +57,8 @@ def _set_value_by_key_path(obj, parts, value):
5157
FIELD_NAME = "[A-Za-z0-9_]*"
5258

5359

54-
def parse_form_data(form_data: List[Tuple]):
55-
result_dict = {}
60+
def parse_form_data(form_data: List[Tuple]) -> Dict[str, FormDataDictType]:
61+
result_dict: Dict[str, FormDataDictType] = {}
5662

5763
for key, value in form_data:
5864
first_match = re.match(rf"({FIELD_NAME})", key)

tests/integration/self_testing/commands/export/01_strictdoc_smoke_test/test.itest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ RUN: %check_exists --file "%S/Output/html/_source_files/strictdoc/core/traceabil
103103

104104
RUN: %cat %S/Output/html/strictdoc/docs/strictdoc_21_L2_StrictDoc_Requirements.html | filecheck %s --check-prefix CHECK-3-REQUIREMENTS
105105
CHECK-3-REQUIREMENTS: href="../../_source_files/strictdoc/core/traceability_index_builder.py.html#SDOC-SRS-30#{{.*}}#{{.*}}"
106-
CHECK-3-REQUIREMENTS: href="../../_source_files/strictdoc/core/tree_cycle_detector.py.html#SDOC-SRS-30#1#73"
106+
CHECK-3-REQUIREMENTS: href="../../_source_files/strictdoc/core/tree_cycle_detector.py.html#SDOC-SRS-30#1#75"
107107

108108
RUN: %cat "%S/Output/html/_source_files/strictdoc/core/tree_cycle_detector.py.html" | filecheck %s --check-prefix CHECK-TREE-CYCLE-DETECTOR
109109
CHECK-TREE-CYCLE-DETECTOR: href="../../../strictdoc/docs/strictdoc_21_L2_StrictDoc_Requirements.html#SDOC-SRS-30"

0 commit comments

Comments
 (0)