mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Migrate to py3 style type annotation: sphinx.parsers
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user