diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-16 00:32:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-16 00:32:10 +0900 |
commit | c70e65fc6cd04d02df4f7911025f534dbd27cc20 (patch) | |
tree | 1e8614ac5516dace99ef1df4d203081662c7c2d6 /sphinx/util/matching.py | |
parent | d6d4406ce987cc8823d1b3a33be3a418bcd2a59d (diff) | |
parent | 79eec90f36f5a74e24cfd6740126396fd6567e07 (diff) | |
download | sphinx-git-c70e65fc6cd04d02df4f7911025f534dbd27cc20.tar.gz |
Merge branch 'master' into 5770_doctest_refers_highlight_language
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. |