summaryrefslogtreecommitdiffstats
path: root/sphinx/util/rst.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sphinx/util/rst.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/sphinx/util/rst.py b/sphinx/util/rst.py
index 1e8fd66..4e8fdee 100644
--- a/sphinx/util/rst.py
+++ b/sphinx/util/rst.py
@@ -5,11 +5,11 @@ from __future__ import annotations
import re
from collections import defaultdict
from contextlib import contextmanager
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, cast
from unicodedata import east_asian_width
from docutils.parsers.rst import roles
-from docutils.parsers.rst.languages import en as english
+from docutils.parsers.rst.languages import en as english # type: ignore[attr-defined]
from docutils.parsers.rst.states import Body
from docutils.utils import Reporter
from jinja2 import Environment, pass_environment
@@ -18,7 +18,7 @@ from sphinx.locale import __
from sphinx.util import docutils, logging
if TYPE_CHECKING:
- from collections.abc import Generator
+ from collections.abc import Iterator
from docutils.statemachine import StringList
@@ -54,17 +54,18 @@ def textwidth(text: str, widechars: str = 'WF') -> int:
def heading(env: Environment, text: str, level: int = 1) -> str:
"""Create a heading for *level*."""
assert level <= 3
- width = textwidth(text, WIDECHARS[env.language])
+ # ``env.language`` is injected by ``sphinx.util.template.ReSTRenderer``
+ width = textwidth(text, WIDECHARS[env.language]) # type: ignore[attr-defined]
sectioning_char = SECTIONING_CHARS[level - 1]
return f'{text}\n{sectioning_char * width}'
@contextmanager
-def default_role(docname: str, name: str) -> Generator[None, None, None]:
+def default_role(docname: str, name: str) -> Iterator[None]:
if name:
dummy_reporter = Reporter('', 4, 4)
role_fn, _ = roles.role(name, english, 0, dummy_reporter)
- if role_fn: # type: ignore[truthy-function]
+ if role_fn:
docutils.register_role('', role_fn) # type: ignore[arg-type]
else:
logger.warning(__('default role %s not found'), name, location=docname)
@@ -102,6 +103,7 @@ def append_epilog(content: StringList, epilog: str) -> None:
if epilog:
if len(content) > 0:
source, lineno = content.info(-1)
+ lineno = cast(int, lineno) # lineno will never be None, since len(content) > 0
else:
source = '<generated>'
lineno = 0