Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-24 19:39:02 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-24 19:57:08 +0300
commit55fff64fbec32e919656f2d0b4d1baf4ee6e981c (patch)
tree31887833b6f695df09285e0d2c4822e0f35d6381 /sphinx/parsers.py
parent16d4ee2582155bddeaea29ef7d28e4b1dcd3b846 (diff)
Migrate to py3 style type annotation: sphinx.parsers
Diffstat (limited to 'sphinx/parsers.py')
-rw-r--r--sphinx/parsers.py24
1 files changed, 10 insertions, 14 deletions
diff --git a/sphinx/parsers.py b/sphinx/parsers.py
index f228fb31b..6c09d65b2 100644
--- a/sphinx/parsers.py
+++ b/sphinx/parsers.py
@@ -8,8 +8,11 @@
:license: BSD, see LICENSE for details.
"""
+from typing import Any, Dict, List, Union
+
import docutils.parsers
import docutils.parsers.rst
+from docutils import nodes
from docutils.parsers.rst import states
from docutils.statemachine import StringList
from docutils.transforms.universal import SmartQuotes
@@ -18,11 +21,9 @@ from sphinx.util.rst import append_epilog, prepend_prolog
if False:
# For type annotation
- from typing import Any, Dict, List, Union # NOQA
- from typing import Type # for python3.5.1
- from docutils import nodes # NOQA
from docutils.transforms import Transform # NOQA
- from sphinx.application import Sphinx # NOQA
+ from typing import Type # NOQA # for python3.5.1
+ from sphinx.application import Sphinx
class Parser(docutils.parsers.Parser):
@@ -48,8 +49,7 @@ class Parser(docutils.parsers.Parser):
``warn()`` and ``info()`` is deprecated. Use :mod:`sphinx.util.logging` instead.
"""
- def set_application(self, app):
- # type: (Sphinx) -> None
+ def set_application(self, app: "Sphinx") -> None:
"""set_application will be called from Sphinx to set app and other instance variables
:param sphinx.application.Sphinx app: Sphinx application object
@@ -62,8 +62,7 @@ class Parser(docutils.parsers.Parser):
class RSTParser(docutils.parsers.rst.Parser, Parser):
"""A reST parser for Sphinx."""
- def get_transforms(self):
- # type: () -> List[Type[Transform]]
+ def get_transforms(self) -> List["Type[Transform]"]:
"""Sphinx's reST parser replaces a transform class for smart-quotes by own's
refs: sphinx.io.SphinxStandaloneReader
@@ -72,8 +71,7 @@ class RSTParser(docutils.parsers.rst.Parser, Parser):
transforms.remove(SmartQuotes)
return transforms
- def parse(self, inputstring, document):
- # type: (Union[str, StringList], nodes.document) -> None
+ def parse(self, inputstring: Union[str, StringList], document: nodes.document) -> None:
"""Parse text and generate a document tree."""
self.setup_parse(inputstring, document) # type: ignore
self.statemachine = states.RSTStateMachine(
@@ -95,15 +93,13 @@ class RSTParser(docutils.parsers.rst.Parser, Parser):
self.statemachine.run(inputlines, document, inliner=self.inliner)
self.finish_parse()
- def decorate(self, content):
- # type: (StringList) -> None
+ def decorate(self, content: StringList) -> None:
"""Preprocess reST content before parsing."""
prepend_prolog(content, self.config.rst_prolog)
append_epilog(content, self.config.rst_epilog)
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
app.add_source_parser(RSTParser)
return {