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-07-03 17:48:01 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-07-06 08:38:45 +0300
commit32fa96d46d7383c83128f516d684bfaa8a54f821 (patch)
treeddb8c43a6c3f7c32b8d0b0c3597b17a57db36315 /sphinx/testing
parent8b4e54f90413d26c60476ce8acdd908fbfc05a82 (diff)
Migrate to py3 style type annotation: sphinx.testing.util
Diffstat (limited to 'sphinx/testing')
-rw-r--r--sphinx/testing/util.py54
1 files changed, 18 insertions, 36 deletions
diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py
index 7b73059e9..1ba3237c4 100644
--- a/sphinx/testing/util.py
+++ b/sphinx/testing/util.py
@@ -11,6 +11,7 @@ import os
import re
import sys
import warnings
+from typing import Any, Dict, Generator, IO, List, Pattern
from xml.etree import ElementTree
from docutils import nodes
@@ -23,10 +24,6 @@ from sphinx.pycode import ModuleAnalyzer
from sphinx.testing.path import path
from sphinx.util.osutil import relpath
-if False:
- # For type annotation
- from typing import Any, Dict, Generator, IO, List, Pattern # NOQA
-
__all__ = [
'Struct',
@@ -35,26 +32,22 @@ __all__ = [
]
-def assert_re_search(regex, text, flags=0):
- # type: (Pattern, str, int) -> None
+def assert_re_search(regex: Pattern, text: str, flags: int = 0) -> None:
if not re.search(regex, text, flags):
assert False, '%r did not match %r' % (regex, text)
-def assert_not_re_search(regex, text, flags=0):
- # type: (Pattern, str, int) -> None
+def assert_not_re_search(regex: Pattern, text: str, flags: int = 0) -> None:
if re.search(regex, text, flags):
assert False, '%r did match %r' % (regex, text)
-def assert_startswith(thing, prefix):
- # type: (str, str) -> None
+def assert_startswith(thing: str, prefix: str) -> None:
if not thing.startswith(prefix):
assert False, '%r does not start with %r' % (thing, prefix)
-def assert_node(node, cls=None, xpath="", **kwargs):
- # type: (nodes.Node, Any, str, Any) -> None
+def assert_node(node: nodes.Node, cls: Any = None, xpath: str = "", **kwargs) -> None:
if cls:
if isinstance(cls, list):
assert_node(node, cls[0], xpath=xpath, **kwargs)
@@ -92,16 +85,14 @@ def assert_node(node, cls=None, xpath="", **kwargs):
'The node%s[%s] is not %r: %r' % (xpath, key, value, node[key])
-def etree_parse(path):
- # type: (str) -> Any
+def etree_parse(path: str) -> Any:
with warnings.catch_warnings(record=False):
warnings.filterwarnings("ignore", category=DeprecationWarning)
return ElementTree.parse(path)
class Struct:
- def __init__(self, **kwds):
- # type: (Any) -> None
+ def __init__(self, **kwds) -> None:
self.__dict__.update(kwds)
@@ -111,10 +102,9 @@ class SphinxTestApp(application.Sphinx):
better default values for the initialization parameters.
"""
- def __init__(self, buildername='html', srcdir=None,
- freshenv=False, confoverrides=None, status=None, warning=None,
- tags=None, docutilsconf=None):
- # type: (str, path, bool, Dict, IO, IO, List[str], str) -> None
+ def __init__(self, buildername: str = 'html', srcdir: path = None, freshenv: bool = False,
+ confoverrides: Dict = None, status: IO = None, warning: IO = None,
+ tags: List[str] = None, docutilsconf: str = None) -> None:
if docutilsconf is not None:
(srcdir / 'docutils.conf').write_text(docutilsconf)
@@ -144,8 +134,7 @@ class SphinxTestApp(application.Sphinx):
self.cleanup()
raise
- def cleanup(self, doctrees=False):
- # type: (bool) -> None
+ def cleanup(self, doctrees: bool = False) -> None:
ModuleAnalyzer.cache.clear()
LaTeXBuilder.usepackages = []
locale.translators.clear()
@@ -159,8 +148,7 @@ class SphinxTestApp(application.Sphinx):
delattr(nodes.GenericNodeVisitor, 'visit_' + method[6:])
delattr(nodes.GenericNodeVisitor, 'depart_' + method[6:])
- def __repr__(self):
- # type: () -> str
+ def __repr__(self) -> str:
return '<%s buildername=%r>' % (self.__class__.__name__, self.builder.name)
@@ -171,16 +159,13 @@ class SphinxTestAppWrapperForSkipBuilding:
file.
"""
- def __init__(self, app_):
- # type: (SphinxTestApp) -> None
+ def __init__(self, app_: SphinxTestApp) -> None:
self.app = app_
- def __getattr__(self, name):
- # type: (str) -> Any
+ def __getattr__(self, name: str) -> Any:
return getattr(self.app, name)
- def build(self, *args, **kw):
- # type: (Any, Any) -> None
+ def build(self, *args, **kw) -> None:
if not self.app.outdir.listdir(): # type: ignore
# if listdir is empty, do build.
self.app.build(*args, **kw)
@@ -190,15 +175,13 @@ class SphinxTestAppWrapperForSkipBuilding:
_unicode_literals_re = re.compile(r'u(".*?")|u(\'.*?\')')
-def remove_unicode_literals(s):
- # type: (str) -> str
+def remove_unicode_literals(s: str) -> str:
warnings.warn('remove_unicode_literals() is deprecated.',
RemovedInSphinx40Warning, stacklevel=2)
return _unicode_literals_re.sub(lambda x: x.group(1) or x.group(2), s)
-def find_files(root, suffix=None):
- # type: (str, bool) -> Generator
+def find_files(root: str, suffix: bool = None) -> Generator[str, None, None]:
for dirpath, dirs, files in os.walk(root, followlinks=True):
dirpath = path(dirpath)
for f in [f for f in files if not suffix or f.endswith(suffix)]: # type: ignore
@@ -206,6 +189,5 @@ def find_files(root, suffix=None):
yield relpath(fpath, root)
-def strip_escseq(text):
- # type: (str) -> str
+def strip_escseq(text: str) -> str:
return re.sub('\x1b.*?m', '', text)