Skip to content

Commit 38a7ba5

Browse files
authored
Merge pull request #2409 from strictdoc-project/stanislaw/markers
Code climate: mypy: fix several remaining union-attr issues
2 parents 732ad01 + 77955a4 commit 38a7ba5

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

.link_health.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exceptions:
1515
- url: https://github.com/mull-project/FileCheck.py/blob/main/pyproject.toml
1616
- url: https://github.com/strictdoc-project/strictdoc/blob/main/docs/strictdoc_01_user_guide.sdoc
1717
- url: https://github.com/strictdoc-project/strictdoc/blob/5c94aab96da4ca21944774f44b2c88509be9636e/tasks.py
18+
- url: https://github.com/strictdoc-project/strictdoc/blob/6f57747e6a1b5b3cb29c0047f9df5959da64ebb1/docs/sdoc_project_statistics.py
1819
- url: https://github.com/strictdoc-project/strictdoc/blob/main/strictdoc/backend/sdoc/grammar/grammar.py
1920
- url: https://github.com/textX/textX/blob/master/LICENSE.txt
2021
- url: https://github.com/sphinx-doc/sphinx/blob/master/LICENSE.rst

strictdoc/backend/sdoc/models/document_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def __init__(
3030
self,
3131
*,
3232
parent: Optional["DocumentConfig"] = None,
33-
entries: Optional[List[DocumentCustomMetadataKeyValuePair]],
33+
entries: List[DocumentCustomMetadataKeyValuePair],
3434
) -> None:
3535
_ = parent
36-
self.entries = entries
36+
self.entries: List[DocumentCustomMetadataKeyValuePair] = entries
3737

3838

3939
@auto_described

strictdoc/backend/sdoc/models/model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ class SDocNodeFieldIF(ABC):
5252
class SDocNodeIF(ABC):
5353
reserved_mid: MID
5454
node_type: str
55+
section_contents: List["SDocElementIF"]
5556
ng_level: Optional[int]
5657
ng_resolved_custom_level: Optional[str]
57-
section_contents: List["SDocElementIF"]
58+
ng_whitelisted: bool
5859

5960
# FIXME: Get rid of @property everywhere.
6061
@property
@@ -96,9 +97,10 @@ def get_prefix(self) -> Optional[str]:
9697

9798
class SDocSectionIF(ABC):
9899
parent: Union["SDocDocumentIF", "SDocSectionIF"]
100+
section_contents: List["SDocElementIF"]
99101
ng_level: Optional[int]
100102
ng_resolved_custom_level: Optional[str]
101-
section_contents: List["SDocElementIF"]
103+
ng_whitelisted: bool
102104

103105
@abstractmethod
104106
def get_document(self) -> Optional["SDocDocumentIF"]:
@@ -122,13 +124,14 @@ class SDocGrammarIF:
122124

123125

124126
class SDocDocumentIF(ABC):
127+
section_contents: List["SDocElementIF"]
128+
included_documents: List["SDocDocumentIF"]
125129
config: DocumentConfig
126130
grammar: Optional[SDocGrammarIF]
127131
meta: Optional[DocumentMeta]
128-
section_contents: List["SDocElementIF"]
129-
included_documents: List["SDocDocumentIF"]
130132
is_bundle_document: bool
131133
ng_level: Optional[int]
134+
ng_whitelisted: bool
132135

133136
@abstractmethod
134137
def get_prefix(self) -> str:
@@ -156,6 +159,7 @@ def ng_resolved_custom_level(self) -> Optional[str]:
156159
class SDocDocumentFromFileIF(ABC):
157160
parent: Union[SDocDocumentIF, SDocSectionIF]
158161
ng_resolved_custom_level: Optional[str]
162+
ng_whitelisted: bool
159163

160164
@abstractmethod
161165
def iterate_nodes(

strictdoc/backend/sdoc/models/section.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@relation(SDOC-SRS-99, scope=file)
33
"""
44

5-
# mypy: disable-error-code="union-attr"
65
from typing import List, Optional, Union
76

87
from strictdoc.backend.sdoc.document_reference import DocumentReference
@@ -99,19 +98,23 @@ def get_display_title(self, include_toc_number: bool = True) -> str:
9998
return self.title
10099

101100
def get_document(self) -> Optional[SDocDocumentIF]:
101+
assert self.ng_document_reference is not None
102102
return self.ng_document_reference.get_document()
103103

104104
def get_including_document(self) -> Optional[SDocDocumentIF]:
105+
assert self.ng_including_document_reference is not None
105106
return self.ng_including_document_reference.get_document()
106107

107108
@property
108109
def parent_or_including_document(self) -> SDocDocumentIF:
110+
assert self.ng_including_document_reference is not None
109111
including_document_or_none = (
110112
self.ng_including_document_reference.get_document()
111113
)
112114
if including_document_or_none is not None:
113115
return including_document_or_none
114116

117+
assert self.ng_document_reference is not None
115118
document: Optional[SDocDocumentIF] = (
116119
self.ng_document_reference.get_document()
117120
)
@@ -121,6 +124,7 @@ def parent_or_including_document(self) -> SDocDocumentIF:
121124
return document
122125

123126
def document_is_included(self) -> bool:
127+
assert self.ng_including_document_reference is not None
124128
return self.ng_including_document_reference.get_document() is not None
125129

126130
def is_requirement(self) -> bool:
@@ -130,8 +134,9 @@ def is_section(self) -> bool:
130134
return True
131135

132136
def has_any_text_nodes(self) -> bool:
137+
# FIXME: Remove using __class__.
133138
return any(
134-
node_.__class__.__name__ == "SDocNode" and node_.node_type == "TEXT"
139+
node_.__class__.__name__ == "SDocNode" and node_.node_type == "TEXT" # type: ignore[union-attr]
135140
for node_ in self.section_contents
136141
)
137142

strictdoc/backend/sdoc/writer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
import os.path
32
from pathlib import Path
43
from typing import Dict, List, Tuple
@@ -438,6 +437,8 @@ def _print_section(
438437
def _print_requirement_fields(
439438
self, section_content: SDocNode, document: SDocDocument
440439
) -> str:
440+
assert document.grammar is not None
441+
441442
output = ""
442443

443444
current_view: ViewElement = document.view.get_current_view(

strictdoc/helpers/form_data.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# mypy: disable-error-code="union-attr"
21
import re
3-
from typing import Dict, List, Tuple, Union
2+
from typing import Dict, List, Match, Optional, Tuple, Union
43

54
from typing_extensions import TypeAlias
65

@@ -98,7 +97,10 @@ def parse_form_data(
9897
result_dict: ParsedFormData = {}
9998

10099
for key, value in form_data:
101-
first_match = re.match(rf"({FIELD_NAME})", key)
100+
first_match: Optional[Match[str]] = re.match(rf"({FIELD_NAME})", key)
101+
102+
assert first_match is not None, "first_match must not be None."
103+
102104
match_groups = first_match.groups()
103105
assert len(match_groups) == 1
104106

0 commit comments

Comments
 (0)