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>2016-11-08 08:05:58 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2016-11-16 06:06:22 +0300
commitceec82451bfbefc0fd720bbf48e4b9a029cacd99 (patch)
tree1d76b5d59db131fb574cd649e0c283534fd6710f /sphinx/versioning.py
parent3407ef0ca8a8ce41e67092d2605f8fc77bebb982 (diff)
Add type-check annotations to sphinx.*
Diffstat (limited to 'sphinx/versioning.py')
-rw-r--r--sphinx/versioning.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/sphinx/versioning.py b/sphinx/versioning.py
index f6c446b4f..0f862ac67 100644
--- a/sphinx/versioning.py
+++ b/sphinx/versioning.py
@@ -16,6 +16,11 @@ from itertools import product
from six import iteritems
from six.moves import range, zip_longest
+if False:
+ # For type annotation
+ from typing import Any, Iterator # NOQA
+ from docutils import nodes # NOQA
+
try:
import Levenshtein
IS_SPEEDUP = True
@@ -27,6 +32,7 @@ VERSIONING_RATIO = 65
def add_uids(doctree, condition):
+ # type: (nodes.Node, Any) -> Iterator[nodes.Node]
"""Add a unique id to every node in the `doctree` which matches the
condition and yield the nodes.
@@ -42,6 +48,7 @@ def add_uids(doctree, condition):
def merge_doctrees(old, new, condition):
+ # type: (nodes.Node, nodes.Node, Any) -> Iterator[nodes.Node]
"""Merge the `old` doctree with the `new` one while looking at nodes
matching the `condition`.
@@ -90,7 +97,7 @@ def merge_doctrees(old, new, condition):
# choose the old node with the best ratio for each new node and set the uid
# as long as the ratio is under a certain value, in which case we consider
# them not changed but different
- ratios = sorted(iteritems(ratios), key=itemgetter(1))
+ ratios = sorted(iteritems(ratios), key=itemgetter(1)) # type: ignore
for (old_node, new_node), ratio in ratios:
if new_node in seen:
continue
@@ -109,6 +116,7 @@ def merge_doctrees(old, new, condition):
def get_ratio(old, new):
+ # type: (unicode, unicode) -> float
"""Return a "similiarity ratio" (in percent) representing the similarity
between the two strings where 0 is equal and anything above less than equal.
"""
@@ -122,6 +130,7 @@ def get_ratio(old, new):
def levenshtein_distance(a, b):
+ # type: (unicode, unicode) -> int
"""Return the Levenshtein edit distance between two strings *a* and *b*."""
if a == b:
return 0
@@ -137,5 +146,5 @@ def levenshtein_distance(a, b):
deletions = current_row[j] + 1
substitutions = previous_row[j] + (column1 != column2)
current_row.append(min(insertions, deletions, substitutions))
- previous_row = current_row
+ previous_row = current_row # type: ignore
return previous_row[-1]