diff options
Diffstat (limited to 'sphinx/testing/path.py')
-rw-r--r-- | sphinx/testing/path.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py index 5836d2bc0..209046246 100644 --- a/sphinx/testing/path.py +++ b/sphinx/testing/path.py @@ -13,6 +13,10 @@ from io import open from six import PY2, text_type +if False: + # For type annotation + from typing import Any, Callable, IO, List # NOQA + FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() @@ -23,58 +27,68 @@ class path(text_type): """ if PY2: def __new__(cls, s, encoding=FILESYSTEMENCODING, errors='strict'): + # type: (unicode, unicode, unicode) -> path if isinstance(s, str): s = s.decode(encoding, errors) - return text_type.__new__(cls, s) # type: ignore + return text_type.__new__(cls, s) return text_type.__new__(cls, s) # type: ignore @property def parent(self): + # type: () -> path """ The name of the directory the file or directory is in. """ return self.__class__(os.path.dirname(self)) def basename(self): + # type: () -> unicode return os.path.basename(self) def abspath(self): + # type: () -> path """ Returns the absolute path. """ return self.__class__(os.path.abspath(self)) def isabs(self): + # type: () -> bool """ Returns ``True`` if the path is absolute. """ return os.path.isabs(self) def isdir(self): + # type: () -> bool """ Returns ``True`` if the path is a directory. """ return os.path.isdir(self) def isfile(self): + # type: () -> bool """ Returns ``True`` if the path is a file. """ return os.path.isfile(self) def islink(self): + # type: () -> bool """ Returns ``True`` if the path is a symbolic link. """ return os.path.islink(self) def ismount(self): + # type: () -> bool """ Returns ``True`` if the path is a mount point. """ return os.path.ismount(self) def rmtree(self, ignore_errors=False, onerror=None): + # type: (bool, Callable) -> None """ Removes the file or directory and any files or directories it may contain. @@ -93,6 +107,7 @@ class path(text_type): shutil.rmtree(self, ignore_errors=ignore_errors, onerror=onerror) def copytree(self, destination, symlinks=False): + # type: (unicode, bool) -> None """ Recursively copy a directory to the given `destination`. If the given `destination` does not exist it will be created. @@ -105,6 +120,7 @@ class path(text_type): shutil.copytree(self, destination, symlinks=symlinks) def movetree(self, destination): + # type: (unicode) -> None """ Recursively move the file or directory to the given `destination` similar to the Unix "mv" command. @@ -117,24 +133,29 @@ class path(text_type): move = movetree def unlink(self): + # type: () -> None """ Removes a file. """ os.unlink(self) def stat(self): + # type: () -> Any """ Returns a stat of the file. """ return os.stat(self) def utime(self, arg): + # type: (Any) -> None os.utime(self, arg) def open(self, mode='r', **kwargs): + # type: (unicode, Any) -> IO return open(self, mode, **kwargs) def write_text(self, text, encoding='utf-8', **kwargs): + # type: (unicode, unicode, Any) -> None """ Writes the given `text` to the file. """ @@ -144,6 +165,7 @@ class path(text_type): f.write(text) def text(self, encoding='utf-8', **kwargs): + # type: (unicode, Any) -> unicode """ Returns the text in the file. """ @@ -152,6 +174,7 @@ class path(text_type): return f.read() def bytes(self): + # type: () -> str """ Returns the bytes in the file. """ @@ -159,6 +182,7 @@ class path(text_type): return f.read() def write_bytes(self, bytes, append=False): + # type: (str, bool) -> None """ Writes the given `bytes` to the file. @@ -173,12 +197,14 @@ class path(text_type): f.write(bytes) def exists(self): + # type: () -> bool """ Returns ``True`` if the path exist. """ return os.path.exists(self) def lexists(self): + # type: () -> bool """ Returns ``True`` if the path exists unless it is a broken symbolic link. @@ -186,21 +212,25 @@ class path(text_type): return os.path.lexists(self) def makedirs(self, mode=0o777): + # type: (int) -> None """ Recursively create directories. """ os.makedirs(self, mode) def joinpath(self, *args): + # type: (Any) -> path """ Joins the path with the argument given and returns the result. """ - return self.__class__(os.path.join(self, *map(self.__class__, args))) + return self.__class__(os.path.join(self, *map(self.__class__, args))) # type: ignore # NOQA def listdir(self): + # type: () -> List[unicode] return os.listdir(self) __div__ = __truediv__ = joinpath def __repr__(self): + # type: () -> str return '%s(%s)' % (self.__class__.__name__, text_type.__repr__(self)) |