summaryrefslogtreecommitdiff
path: root/sphinx/addnodes.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-25 11:41:54 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-25 11:41:54 +0900
commitd717f5ae31d17533a5a20b581f571eb4a95b1b30 (patch)
tree65bb3a38edc57d2b5e70b19ca8996ccebd1e3951 /sphinx/addnodes.py
parentd82e7c12a177a6a547ba1e72540f079f64590f8a (diff)
parent869ba4f67947b97af90dc706fb7e6ed17946ccd3 (diff)
downloadsphinx-git-d717f5ae31d17533a5a20b581f571eb4a95b1b30.tar.gz
Merge branch '2.0'
Diffstat (limited to 'sphinx/addnodes.py')
-rw-r--r--sphinx/addnodes.py34
1 files changed, 12 insertions, 22 deletions
diff --git a/sphinx/addnodes.py b/sphinx/addnodes.py
index e0e49a9b9..7b1edc018 100644
--- a/sphinx/addnodes.py
+++ b/sphinx/addnodes.py
@@ -9,6 +9,7 @@
"""
import warnings
+from typing import Any, Dict, List, Sequence
from docutils import nodes
@@ -16,8 +17,7 @@ from sphinx.deprecation import RemovedInSphinx40Warning
if False:
# For type annotation
- from typing import Any, Dict, List, Sequence # NOQA
- from sphinx.application import Sphinx # NOQA
+ from sphinx.application import Sphinx
class translatable(nodes.Node):
@@ -34,18 +34,15 @@ class translatable(nodes.Node):
Because they are used at final step; extraction.
"""
- def preserve_original_messages(self):
- # type: () -> None
+ def preserve_original_messages(self) -> None:
"""Preserve original translatable messages."""
raise NotImplementedError
- def apply_translated_message(self, original_message, translated_message):
- # type: (str, str) -> None
+ def apply_translated_message(self, original_message: str, translated_message: str) -> None:
"""Apply translated message."""
raise NotImplementedError
- def extract_original_messages(self):
- # type: () -> Sequence[str]
+ def extract_original_messages(self) -> Sequence[str]:
"""Extract translation messages.
:returns: list of extracted messages or messages generator
@@ -61,8 +58,7 @@ class not_smartquotable:
class toctree(nodes.General, nodes.Element, translatable):
"""Node for inserting a "TOC tree"."""
- def preserve_original_messages(self):
- # type: () -> None
+ def preserve_original_messages(self) -> None:
# toctree entries
rawentries = self.setdefault('rawentries', [])
for title, docname in self['entries']:
@@ -73,8 +69,7 @@ class toctree(nodes.General, nodes.Element, translatable):
if self.get('caption'):
self['rawcaption'] = self['caption']
- def apply_translated_message(self, original_message, translated_message):
- # type: (str, str) -> None
+ def apply_translated_message(self, original_message: str, translated_message: str) -> None:
# toctree entries
for i, (title, docname) in enumerate(self['entries']):
if title == original_message:
@@ -84,8 +79,7 @@ class toctree(nodes.General, nodes.Element, translatable):
if self.get('rawcaption') == original_message:
self['caption'] = translated_message
- def extract_original_messages(self):
- # type: () -> List[str]
+ def extract_original_messages(self) -> List[str]:
messages = [] # type: List[str]
# toctree entries
@@ -143,8 +137,7 @@ class desc_type(nodes.Part, nodes.Inline, nodes.FixedTextElement):
class desc_returns(desc_type):
"""Node for a "returns" annotation (a la -> in Python)."""
- def astext(self):
- # type: () -> str
+ def astext(self) -> str:
return ' -> ' + super().astext()
@@ -165,8 +158,7 @@ class desc_optional(nodes.Part, nodes.Inline, nodes.FixedTextElement):
"""Node for marking optional parts of the parameter list."""
child_text_separator = ', '
- def astext(self):
- # type: () -> str
+ def astext(self) -> str:
return '[' + super().astext() + ']'
@@ -313,8 +305,7 @@ class abbreviation(nodes.abbreviation):
.. deprecated:: 2.0
"""
- def __init__(self, rawsource='', text='', *children, **attributes):
- # type: (str, str, *nodes.Node, **Any) -> None
+ def __init__(self, rawsource: str = '', text: str = '', *children, **attributes) -> None:
warnings.warn("abbrevition node for Sphinx was replaced by docutils'.",
RemovedInSphinx40Warning, stacklevel=2)
@@ -325,8 +316,7 @@ class manpage(nodes.Inline, nodes.FixedTextElement):
"""Node for references to manpages."""
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
app.add_node(toctree)
app.add_node(desc)
app.add_node(desc_signature)