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-25 05:41:54 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-12-25 05:41:54 +0300
commitd717f5ae31d17533a5a20b581f571eb4a95b1b30 (patch)
tree65bb3a38edc57d2b5e70b19ca8996ccebd1e3951 /sphinx/versioning.py
parentd82e7c12a177a6a547ba1e72540f079f64590f8a (diff)
parent869ba4f67947b97af90dc706fb7e6ed17946ccd3 (diff)
Merge branch '2.0'
Diffstat (limited to 'sphinx/versioning.py')
-rw-r--r--sphinx/versioning.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/sphinx/versioning.py b/sphinx/versioning.py
index 56c126da2..0142dfb66 100644
--- a/sphinx/versioning.py
+++ b/sphinx/versioning.py
@@ -12,15 +12,17 @@ import pickle
from itertools import product, zip_longest
from operator import itemgetter
from os import path
+from typing import Any, Dict, Iterator
from uuid import uuid4
+from docutils import nodes
+from docutils.nodes import Node
+
from sphinx.transforms import SphinxTransform
if False:
# For type annotation
- from typing import Any, Dict, Iterator # NOQA
- from docutils import nodes # NOQA
- from sphinx.application import Sphinx # NOQA
+ from sphinx.application import Sphinx
try:
import Levenshtein
@@ -32,8 +34,7 @@ except ImportError:
VERSIONING_RATIO = 65
-def add_uids(doctree, condition):
- # type: (nodes.Node, Any) -> Iterator[nodes.Node]
+def add_uids(doctree: Node, condition: Any) -> Iterator[Node]:
"""Add a unique id to every node in the `doctree` which matches the
condition and yield the nodes.
@@ -48,8 +49,7 @@ def add_uids(doctree, condition):
yield node
-def merge_doctrees(old, new, condition):
- # type: (nodes.Node, nodes.Node, Any) -> Iterator[nodes.Node]
+def merge_doctrees(old: Node, new: Node, condition: Any) -> Iterator[Node]:
"""Merge the `old` doctree with the `new` one while looking at nodes
matching the `condition`.
@@ -116,8 +116,7 @@ def merge_doctrees(old, new, condition):
yield new_node
-def get_ratio(old, new):
- # type: (str, str) -> float
+def get_ratio(old: str, new: str) -> float:
"""Return a "similiarity ratio" (in percent) representing the similarity
between the two strings where 0 is equal and anything above less than equal.
"""
@@ -130,8 +129,7 @@ def get_ratio(old, new):
return levenshtein_distance(old, new) / (len(old) / 100.0)
-def levenshtein_distance(a, b):
- # type: (str, str) -> int
+def levenshtein_distance(a: str, b: str) -> int:
"""Return the Levenshtein edit distance between two strings *a* and *b*."""
if a == b:
return 0
@@ -155,8 +153,7 @@ class UIDTransform(SphinxTransform):
"""Add UIDs to doctree for versioning."""
default_priority = 880
- def apply(self, **kwargs):
- # type: (Any) -> None
+ def apply(self, **kwargs) -> None:
env = self.env
old_doctree = None
if not env.versioning_condition:
@@ -178,8 +175,7 @@ class UIDTransform(SphinxTransform):
list(merge_doctrees(old_doctree, self.document, env.versioning_condition))
-def setup(app):
- # type: (Sphinx) -> Dict[str, Any]
+def setup(app: "Sphinx") -> Dict[str, Any]:
app.add_transform(UIDTransform)
return {