1- # mypy: disable-error-code="union-attr"
21import html
32from 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"
0 commit comments