Migrate to py3 style type annotation: sphinx.errors

This commit is contained in:
Takeshi KOMIYA 2019-12-25 01:28:23 +09:00
parent 4b8937ab29
commit 0a1d9e2b49

View File

@ -9,9 +9,7 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
if False: from typing import Any
# For type annotation
from typing import Any # NOQA
class SphinxError(Exception): class SphinxError(Exception):
@ -51,21 +49,18 @@ class ExtensionError(SphinxError):
"""Extension error.""" """Extension error."""
category = 'Extension error' category = 'Extension error'
def __init__(self, message, orig_exc=None): def __init__(self, message: str, orig_exc: Exception = None) -> None:
# type: (str, Exception) -> None
super().__init__(message) super().__init__(message)
self.message = message self.message = message
self.orig_exc = orig_exc self.orig_exc = orig_exc
def __repr__(self): def __repr__(self) -> str:
# type: () -> str
if self.orig_exc: if self.orig_exc:
return '%s(%r, %r)' % (self.__class__.__name__, return '%s(%r, %r)' % (self.__class__.__name__,
self.message, self.orig_exc) self.message, self.orig_exc)
return '%s(%r)' % (self.__class__.__name__, self.message) return '%s(%r)' % (self.__class__.__name__, self.message)
def __str__(self): def __str__(self) -> str:
# type: () -> str
parent_str = super().__str__() parent_str = super().__str__()
if self.orig_exc: if self.orig_exc:
return '%s (exception: %s)' % (parent_str, self.orig_exc) return '%s (exception: %s)' % (parent_str, self.orig_exc)
@ -102,21 +97,18 @@ class SphinxParallelError(SphinxError):
category = 'Sphinx parallel build error' category = 'Sphinx parallel build error'
def __init__(self, message, traceback): def __init__(self, message: str, traceback: Any) -> None:
# type: (str, Any) -> None
self.message = message self.message = message
self.traceback = traceback self.traceback = traceback
def __str__(self): def __str__(self) -> str:
# type: () -> str
return self.message return self.message
class PycodeError(Exception): class PycodeError(Exception):
"""Pycode Python source code analyser error.""" """Pycode Python source code analyser error."""
def __str__(self): def __str__(self) -> str:
# type: () -> str
res = self.args[0] res = self.args[0]
if len(self.args) > 1: if len(self.args) > 1:
res += ' (exception was: %r)' % self.args[1] res += ' (exception was: %r)' % self.args[1]