diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-25 02:02:05 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-12-25 02:02:06 +0900 |
commit | 4b8937ab29e6750974e34cb0ec0265d62c5894e2 (patch) | |
tree | 29b24db5121c3d8b91aa7f561e3da03b5a936b3b /sphinx/deprecation.py | |
parent | e6094d0aca3fc5fadfaffa7f4a638aaf87785300 (diff) | |
download | sphinx-git-4b8937ab29e6750974e34cb0ec0265d62c5894e2.tar.gz |
Migrate to py3 style type annotation: sphinx.deprecation
Diffstat (limited to 'sphinx/deprecation.py')
-rw-r--r-- | sphinx/deprecation.py | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/sphinx/deprecation.py b/sphinx/deprecation.py index 57f4b3ddf..2d5f999d3 100644 --- a/sphinx/deprecation.py +++ b/sphinx/deprecation.py @@ -11,11 +11,8 @@ import sys import warnings from importlib import import_module - -if False: - # For type annotation - from typing import Any, Dict # NOQA - from typing import Type # for python3.5.1 +from typing import Any, Dict +from typing import Type # for python3.5.1 class RemovedInSphinx30Warning(DeprecationWarning): @@ -29,22 +26,20 @@ class RemovedInSphinx40Warning(PendingDeprecationWarning): RemovedInNextVersionWarning = RemovedInSphinx30Warning -def deprecated_alias(modname, objects, warning): - # type: (str, Dict, Type[Warning]) -> None +def deprecated_alias(modname: str, objects: Dict, warning: Type[Warning]) -> None: module = import_module(modname) sys.modules[modname] = _ModuleWrapper(module, modname, objects, warning) # type: ignore class _ModuleWrapper: - def __init__(self, module, modname, objects, warning): - # type: (Any, str, Dict, Type[Warning]) -> None + def __init__(self, module: Any, modname: str, objects: Dict, warning: Type[Warning] + ) -> None: self._module = module self._modname = modname self._objects = objects self._warning = warning - def __getattr__(self, name): - # type: (str) -> Any + def __getattr__(self, name: str) -> Any: if name in self._objects: warnings.warn("%s.%s is deprecated. Check CHANGES for Sphinx " "API modifications." % (self._modname, name), @@ -57,33 +52,27 @@ class _ModuleWrapper: class DeprecatedDict(dict): """A deprecated dict which warns on each access.""" - def __init__(self, data, message, warning): - # type: (Dict, str, Type[Warning]) -> None + def __init__(self, data: Dict, message: str, warning: Type[Warning]) -> None: self.message = message self.warning = warning super().__init__(data) - def __setitem__(self, key, value): - # type: (str, Any) -> None + def __setitem__(self, key: str, value: Any) -> None: warnings.warn(self.message, self.warning, stacklevel=2) super().__setitem__(key, value) - def setdefault(self, key, default=None): - # type: (str, Any) -> None + def setdefault(self, key: str, default: Any = None) -> Any: warnings.warn(self.message, self.warning, stacklevel=2) return super().setdefault(key, default) - def __getitem__(self, key): - # type: (str) -> None + def __getitem__(self, key: str) -> None: warnings.warn(self.message, self.warning, stacklevel=2) return super().__getitem__(key) - def get(self, key, default=None): - # type: (str, Any) -> None + def get(self, key: str, default: Any = None) -> Any: warnings.warn(self.message, self.warning, stacklevel=2) return super().get(key, default) - def update(self, other=None): # type: ignore - # type: (Dict) -> None + def update(self, other: Dict = None) -> None: # type: ignore warnings.warn(self.message, self.warning, stacklevel=2) super().update(other) |