Skip to content

Commit f007875

Browse files
committed
LinkTree: Fix type hinting
1 parent 71184b7 commit f007875

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ jobs:
102102
# Install specific Sphinx and docutils versions, according to test matrix slots.
103103
uv pip install 'sphinx==${{ matrix.sphinx-version }}'
104104
uv pip install 'docutils==${{ matrix.docutils-version }}'
105+
uv pip install 'types-docutils==${{ matrix.docutils-version }}'
105106
106107
- name: Sphinx and docutils versions
107108
run: |

sphinx_design_elements/hyper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import yaml
77
from docutils import nodes
8-
from docutils.nodes import Node, system_message, unescape
8+
from docutils.nodes import Node, system_message, unescape # type: ignore[attr-defined]
99
from docutils.parsers.rst.states import Inliner
1010
from myst_parser.mocking import MockInliner
1111
from sphinx.application import Sphinx
@@ -141,8 +141,8 @@ def __call__(
141141

142142
else:
143143
error = ValueError("Unable to resolve reference")
144-
msg = inliner.reporter.warning(error)
145-
prb = inliner.problematic(rawtext, rawtext, msg)
144+
msg = inliner.reporter.warning(error) # type: ignore[union-attr]
145+
prb = inliner.problematic(rawtext, rawtext, msg) # type: ignore[union-attr]
146146
return [prb], [msg]
147147

148148
return SphinxRole.__call__(self, name, rawtext, text, lineno, inliner, options, content) # type: ignore[arg-type]
@@ -158,7 +158,7 @@ def resolve_page_title(self) -> str:
158158
except Exception:
159159
return self.target
160160
elif self.srh.is_traditional_intersphinx_reference():
161-
document = self.inliner.document
161+
document = self.inliner.document # type: ignore[attr-defined]
162162
ref = resolve_reference(env=self.app.env, document=document, target=self.target)
163163
elif self.srh.is_myst_reference():
164164
link = f"[]({self.target})"
@@ -308,7 +308,7 @@ def render_snippet(self, snippet: str) -> Tuple[List[nodes.Node], List[nodes.sys
308308
Render a MyST snippet.
309309
"""
310310
directive_nodes, _ = self.inliner.parse_block( # type: ignore[attr-defined]
311-
text=snippet, lineno=self.lineno, memo=self, parent=self.inliner.parent, with_container=self.with_container
311+
text=snippet, lineno=self.lineno, memo=self, parent=self.inliner.parent, with_container=self.with_container # type: ignore[attr-defined]
312312
)
313313
if not directive_nodes:
314314
return [], self.system_messages

sphinx_design_elements/linktree.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import traceback
23
from typing import List
34

@@ -62,7 +63,7 @@ def run(self) -> List[nodes.Node]:
6263
f"The 'linktree' directive currently does not accept content. "
6364
f"The offending node is:\n{self.block_text}"
6465
)
65-
self.reporter.severe(message)
66+
self.reporter.severe(message) # type: ignore[attr-defined]
6667
raise SphinxError(message)
6768

6869
# Create a surrogate node element.
@@ -125,7 +126,8 @@ def produce(self, node: nodes.Element, docname: str) -> nodes.Element:
125126
try:
126127
project.toctree(maxdepth=int(node.get("maxdepth", -1)))
127128
except Exception as ex:
128-
tb = "".join(traceback.format_exception(ex))
129+
exc_type, exc_value, exc_tb = sys.exc_info()
130+
tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
129131
message = (
130132
f"Error producing a toc tree for document using the 'linktree' directive: {docname}. "
131133
f"The offending node is:\n{node}\nThe exception was:\n{tb}"

sphinx_design_elements/util/role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def parse_block_myst(
107107
if with_container:
108108
ref = container.next_node()
109109
else:
110-
ref = cast("nodes.Node", container.next_node()).next_node()
110+
ref = cast("nodes.Node", container.next_node()).next_node() # type: ignore[redundant-cast]
111111
if ref:
112112
return [ref], []
113113
else:

0 commit comments

Comments
 (0)