diff options
Diffstat (limited to 'sphinx/util/matching.py')
-rw-r--r-- | sphinx/util/matching.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py index 7dd8100b4..3762fa89e 100644 --- a/sphinx/util/matching.py +++ b/sphinx/util/matching.py @@ -14,18 +14,17 @@ import re if False: # For type annotation from typing import Callable, Dict, List, Match, Pattern # NOQA - from sphinx.util.typing import unicode # NOQA def _translate_pattern(pat): - # type: (unicode) -> unicode + # type: (str) -> str """Translate a shell-style glob pattern to a regular expression. Adapted from the fnmatch module, but enhanced so that single stars don't match slashes. """ i, n = 0, len(pat) - res = '' # type: unicode + res = '' # type: str while i < n: c = pat[i] i += 1 @@ -65,7 +64,7 @@ def _translate_pattern(pat): def compile_matchers(patterns): - # type: (List[unicode]) -> List[Callable[[unicode], Match[unicode]]] + # type: (List[str]) -> List[Callable[[str], Match[str]]] return [re.compile(_translate_pattern(pat)).match for pat in patterns] @@ -77,27 +76,27 @@ class Matcher: """ def __init__(self, patterns): - # type: (List[unicode]) -> None + # type: (List[str]) -> None expanded = [pat[3:] for pat in patterns if pat.startswith('**/')] self.patterns = compile_matchers(patterns + expanded) def __call__(self, string): - # type: (unicode) -> bool + # type: (str) -> bool return self.match(string) def match(self, string): - # type: (unicode) -> bool + # type: (str) -> bool return any(pat(string) for pat in self.patterns) DOTFILES = Matcher(['**/.*']) -_pat_cache = {} # type: Dict[unicode, Pattern] +_pat_cache = {} # type: Dict[str, Pattern] def patmatch(name, pat): - # type: (unicode, unicode) -> Match[unicode] + # type: (str, str) -> Match[str] """Return if name matches pat. Adapted from fnmatch module.""" if pat not in _pat_cache: _pat_cache[pat] = re.compile(_translate_pattern(pat)) @@ -105,7 +104,7 @@ def patmatch(name, pat): def patfilter(names, pat): - # type: (List[unicode], unicode) -> List[unicode] + # type: (List[str], str) -> List[str] """Return the subset of the list NAMES that match PAT. Adapted from fnmatch module. |