diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-07-06 12:27:15 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-07-06 12:42:26 +0900 |
| commit | 986ac82adff9a700e9549d250f3a1077997ba388 (patch) | |
| tree | 1abf2bb8a3e8f524476d8187a15d3d54b3fbd00c /sphinx/environment | |
| parent | e67e0432b55efc4bcf0bc8794b6a7689714ab72b (diff) | |
| download | sphinx-git-986ac82adff9a700e9549d250f3a1077997ba388.tar.gz | |
Migrate to py3 style type annotation: sphinx.environment.adapters.indexentries
Diffstat (limited to 'sphinx/environment')
| -rw-r--r-- | sphinx/environment/adapters/indexentries.py | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/sphinx/environment/adapters/indexentries.py b/sphinx/environment/adapters/indexentries.py index 38d28f0b0..430c3dce2 100644 --- a/sphinx/environment/adapters/indexentries.py +++ b/sphinx/environment/adapters/indexentries.py @@ -11,33 +11,30 @@ import bisect import re import unicodedata from itertools import groupby +from typing import Any, Dict, Pattern, List, Tuple +from sphinx.builders import Builder +from sphinx.environment import BuildEnvironment from sphinx.errors import NoUri from sphinx.locale import _, __ from sphinx.util import split_into, logging -if False: - # For type annotation - from typing import Any, Dict, Pattern, List, Tuple # NOQA - from sphinx.builders import Builder # NOQA - from sphinx.environment import BuildEnvironment # NOQA logger = logging.getLogger(__name__) class IndexEntries: - def __init__(self, env): - # type: (BuildEnvironment) -> None + def __init__(self, env: BuildEnvironment) -> None: self.env = env - def create_index(self, builder, group_entries=True, - _fixre=re.compile(r'(.*) ([(][^()]*[)])')): - # type: (Builder, bool, Pattern) -> List[Tuple[str, List[Tuple[str, Any]]]] + def create_index(self, builder: Builder, group_entries: bool = True, + _fixre: Pattern = re.compile(r'(.*) ([(][^()]*[)])') + ) -> List[Tuple[str, List[Tuple[str, Any]]]]: """Create the real index from the collected index entries.""" new = {} # type: Dict[str, List] - def add_entry(word, subword, main, link=True, dic=new, key=None): - # type: (str, str, str, bool, Dict, str) -> None + def add_entry(word: str, subword: str, main: str, link: bool = True, + dic: Dict = new, key: str = None) -> None: # Force the word to be unicode if it's a ASCII bytestring. # This will solve problems with unicode normalization later. # For instance the RFC role will add bytestrings at the moment @@ -91,8 +88,7 @@ class IndexEntries: # sort the index entries; put all symbols at the front, even those # following the letters in ASCII, this is where the chr(127) comes from - def keyfunc(entry): - # type: (Tuple[str, List]) -> Tuple[str, str] + def keyfunc(entry: Tuple[str, List]) -> Tuple[str, str]: key, (void, void, category_key) = entry if category_key: # using specified category key to sort @@ -138,8 +134,7 @@ class IndexEntries: i += 1 # group the entries by letter - def keyfunc2(item): - # type: (Tuple[str, List]) -> str + def keyfunc2(item: Tuple[str, List]) -> str: # hack: mutating the subitems dicts to a list in the keyfunc k, v = item v[1] = sorted((si, se) for (si, (se, void, void)) in v[1].items()) |
