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.util.compat
This commit is contained in:
parent
24f8a3caf0
commit
f3e45e485e
@ -10,23 +10,22 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
from docutils.utils import get_source_line
|
from docutils.utils import get_source_line
|
||||||
|
|
||||||
from sphinx import addnodes
|
from sphinx import addnodes
|
||||||
|
from sphinx.config import Config
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
from sphinx.transforms import SphinxTransform
|
from sphinx.transforms import SphinxTransform
|
||||||
from sphinx.util import import_object
|
from sphinx.util import import_object
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
from typing import Any, Dict # NOQA
|
from sphinx.application import Sphinx
|
||||||
from sphinx.application import Sphinx # NOQA
|
|
||||||
from sphinx.config import Config # NOQA
|
|
||||||
|
|
||||||
|
|
||||||
def deprecate_source_parsers(app, config):
|
def deprecate_source_parsers(app: "Sphinx", config: Config) -> None:
|
||||||
# type: (Sphinx, Config) -> None
|
|
||||||
if config.source_parsers:
|
if config.source_parsers:
|
||||||
warnings.warn('The config variable "source_parsers" is deprecated. '
|
warnings.warn('The config variable "source_parsers" is deprecated. '
|
||||||
'Please update your extension for the parser and remove the setting.',
|
'Please update your extension for the parser and remove the setting.',
|
||||||
@ -37,8 +36,7 @@ def deprecate_source_parsers(app, config):
|
|||||||
app.add_source_parser(suffix, parser)
|
app.add_source_parser(suffix, parser)
|
||||||
|
|
||||||
|
|
||||||
def register_application_for_autosummary(app):
|
def register_application_for_autosummary(app: "Sphinx") -> None:
|
||||||
# type: (Sphinx) -> None
|
|
||||||
"""Register application object to autosummary module.
|
"""Register application object to autosummary module.
|
||||||
|
|
||||||
Since Sphinx-1.7, documenters and attrgetters are registered into
|
Since Sphinx-1.7, documenters and attrgetters are registered into
|
||||||
@ -55,8 +53,7 @@ class IndexEntriesMigrator(SphinxTransform):
|
|||||||
"""Migrating indexentries from old style (4columns) to new style (5columns)."""
|
"""Migrating indexentries from old style (4columns) to new style (5columns)."""
|
||||||
default_priority = 700
|
default_priority = 700
|
||||||
|
|
||||||
def apply(self, **kwargs):
|
def apply(self, **kwargs) -> None:
|
||||||
# type: (Any) -> None
|
|
||||||
for node in self.document.traverse(addnodes.index):
|
for node in self.document.traverse(addnodes.index):
|
||||||
for i, entries in enumerate(node['entries']):
|
for i, entries in enumerate(node['entries']):
|
||||||
if len(entries) == 4:
|
if len(entries) == 4:
|
||||||
@ -66,8 +63,7 @@ class IndexEntriesMigrator(SphinxTransform):
|
|||||||
node['entries'][i] = entries + (None,)
|
node['entries'][i] = entries + (None,)
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app: "Sphinx") -> Dict[str, Any]:
|
||||||
# type: (Sphinx) -> Dict[str, Any]
|
|
||||||
app.add_transform(IndexEntriesMigrator)
|
app.add_transform(IndexEntriesMigrator)
|
||||||
app.connect('config-inited', deprecate_source_parsers)
|
app.connect('config-inited', deprecate_source_parsers)
|
||||||
app.connect('builder-inited', register_application_for_autosummary)
|
app.connect('builder-inited', register_application_for_autosummary)
|
||||||
|
Loading…
Reference in New Issue
Block a user