Skip to content

Commit 6c21f3a

Browse files
authored
Merge pull request #2411 from strictdoc-project/stanislaw/markers
Code climate: mypy: fix several remaining union-attr issues
2 parents 5bb9664 + 18c14b7 commit 6c21f3a

File tree

15 files changed

+49
-43
lines changed

15 files changed

+49
-43
lines changed

strictdoc/backend/sdoc/models/anchor.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ def get_document(self) -> SDocDocumentIF:
5555
def get_parent_or_including_document(self) -> SDocDocumentIF:
5656
return self.parent_node().get_parent_or_including_document()
5757

58-
# FIXME: Remove this. Use get_parent_or_including_document() instead.
59-
@property
60-
def parent_or_including_document(self) -> SDocDocumentIF:
61-
return self.get_parent_or_including_document()
62-
6358
def get_including_document(self) -> Optional[SDocDocumentIF]:
6459
return self.parent_node().get_including_document()
6560

strictdoc/backend/sdoc/models/node.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,6 @@ def get_debug_info(self) -> str:
366366
debug_components.append(f"document = {document.get_debug_info()}")
367367
return f"Requirement({', '.join(debug_components)})"
368368

369-
# FIXME: Remove this method. Use get_parent_or_including_document() instead.
370-
@property
371-
def parent_or_including_document(self) -> SDocDocumentIF:
372-
return self.get_parent_or_including_document()
373-
374369
def document_is_included(self) -> bool:
375370
assert self.ng_including_document_reference is not None
376371
return self.ng_including_document_reference.get_document() is not None

strictdoc/backend/sdoc/models/section.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def get_including_document(self) -> Optional[SDocDocumentIF]:
105105
assert self.ng_including_document_reference is not None
106106
return self.ng_including_document_reference.get_document()
107107

108-
@property
109-
def parent_or_including_document(self) -> SDocDocumentIF:
108+
def get_parent_or_including_document(self) -> SDocDocumentIF:
110109
assert self.ng_including_document_reference is not None
111110
including_document_or_none = (
112111
self.ng_including_document_reference.get_document()

strictdoc/export/html/form_objects/rows/row_with_grammar_element_form_object.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
from dataclasses import dataclass
32
from typing import Any, Dict, List
43

strictdoc/export/html/generators/view_objects/document_screen_view_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
from dataclasses import dataclass
32
from datetime import datetime
43
from typing import Any, Iterator, List, Optional, Sequence, Tuple, Union
@@ -305,6 +304,7 @@ def get_document_by_path(self, full_path: str) -> SDocDocument:
305304
)
306305

307306
def get_grammar_elements(self) -> List[GrammarElement]:
307+
assert self.document.grammar is not None
308308
return self.document.grammar.elements
309309

310310
def table_of_contents(

strictdoc/export/html/generators/view_objects/search_screen_view_object.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
from dataclasses import dataclass
32
from typing import Iterator, List, Optional, Union
43

strictdoc/export/html/generators/view_objects/source_file_view_object.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
from dataclasses import dataclass
32
from typing import Any, List, Optional, Union
43

strictdoc/export/html/renderers/link_renderer.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# mypy: disable-error-code="union-attr"
21
import html
32
from typing import Any, Dict, Optional, Tuple, Union
43

@@ -104,11 +103,12 @@ def render_node_link(
104103
), node
105104

106105
if isinstance(node, SDocDocument):
107-
context_level_or_none = (
108-
context_document.meta.level
109-
if context_document is not None
110-
else None
111-
)
106+
context_level_or_none: Optional[int] = None
107+
if context_document is not None:
108+
assert context_document.meta is not None
109+
context_level_or_none = context_document.meta.level
110+
111+
assert node.meta is not None
112112
document_link = node.meta.get_html_link(
113113
document_type,
114114
context_level_or_none,
@@ -133,21 +133,26 @@ def render_node_link(
133133
return f"#{local_link}"
134134

135135
# Now two cases:
136-
# - Context document exists and we want to take into account this
136+
# - Context document exists, and we want to take into account this
137137
# document's depth.
138138
# - Context document does not exist, such as when we are on a Search
139139
# screen. In this case, the level is simply zero.
140-
level: int = (
141-
context_document.meta.level if context_document is not None else 0
142-
) # FIXME 0 or 1?
140+
level: int = 0
141+
if context_document is not None:
142+
assert context_document.meta is not None
143+
level = context_document.meta.level
144+
143145
link_cache_key = (document_type, level)
144146
if link_cache_key in self.req_link_cache:
145147
document_type_cache = self.req_link_cache[link_cache_key]
146148
if node in document_type_cache:
147149
return document_type_cache[node]
148150
else:
149151
self.req_link_cache[link_cache_key] = {}
150-
document_link = node.parent_or_including_document.meta.get_html_link(
152+
153+
parent_or_including_document = node.get_parent_or_including_document()
154+
assert parent_or_including_document.meta is not None
155+
document_link = parent_or_including_document.meta.get_html_link(
151156
document_type,
152157
level,
153158
)
@@ -167,10 +172,13 @@ def render_node_doxygen_link(
167172
"""
168173

169174
assert isinstance(node, (SDocNode, SDocSection, Anchor)), node
175+
176+
parent_or_including_document = node.get_parent_or_including_document()
177+
assert parent_or_including_document is not None
178+
assert parent_or_including_document.meta is not None
179+
170180
local_link = self.render_local_anchor(node)
171-
document_link = (
172-
node.parent_or_including_document.meta.get_html_doc_link()
173-
)
181+
document_link = parent_or_including_document.meta.get_html_doc_link()
174182
requirement_link = f"{document_link}#{local_link}"
175183
return requirement_link
176184

@@ -189,6 +197,7 @@ def render_requirement_link_from_source_file(
189197
self.req_link_cache[link_cache_key] = {}
190198

191199
document = assert_cast(node.get_document(), SDocDocument)
200+
assert document.meta is not None
192201
document_link = document.meta.get_html_link(
193202
DocumentType.DOCUMENT, source_file.level + 1
194203
)
@@ -206,6 +215,7 @@ def render_source_file_link(
206215
document: SDocDocument = assert_cast(
207216
requirement.ng_document_reference.get_document(), SDocDocument
208217
)
218+
assert document.meta is not None
209219
path_prefix = document.meta.get_root_path_prefix()
210220
source_file_link = (
211221
f"{path_prefix}/_source_files/{requirement_source_path}.html"

strictdoc/export/html/templates/rst/anchor.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Incoming link{% if incoming_links|length > 1 -%}s{%- endif %} from:
1414
{%- for incoming_link in incoming_links -%}
1515
{%- set incoming_link_parent_node = incoming_link.parent_node() -%}
16-
{%- set incoming_link_href = link_renderer.render_node_link(incoming_link.parent_node(), anchor.parent_or_including_document, document_type) -%}
16+
{%- set incoming_link_href = link_renderer.render_node_link(incoming_link.parent_node(), anchor.get_parent_or_including_document(), document_type) -%}
1717
<a href="{{ incoming_link_href }}">
1818
{{ incoming_link_parent_node.get_display_title() }}
1919
</a>

strictdoc/export/html/templates/screens/document/_shared/toc.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{{ section.context.title_number_string if section.context.title_number_string else "&nbsp;"|safe * (section.ng_level * 2 - 1) }}
3737
</span>{{- section.title -}}
3838
{# TODO #fragment #}
39-
{# {{ section.document_is_included() }} {{ section.parent_or_including_document.reserved_title }}/{{ section.get_document().reserved_title }} #}
39+
{# {{ section.document_is_included() }} {{ section.get_parent_or_including_document().reserved_title }}/{{ section.get_document().reserved_title }} #}
4040
</a>
4141
{%- endif -%}
4242
{%- else -%}
@@ -52,7 +52,7 @@
5252
{%- if section.reserved_title is not none -%}
5353
{{- section.reserved_title -}}
5454
{# TODO #fragment #}
55-
{# {{ section.document_is_included() }} {{ section.parent_or_including_document.reserved_title }}/{{ section.get_document().reserved_title }} #}
55+
{# {{ section.document_is_included() }} {{ section.get_parent_or_including_document().reserved_title }}/{{ section.get_document().reserved_title }} #}
5656
{%- endif -%}
5757
</a>
5858
{%- endif -%}

0 commit comments

Comments
 (0)