diff --git a/README.md b/README.md index 25bd5b8..0bd2a94 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is an open-source client library communicating with the Mujin Controller We - Versions have three numbers: MAJOR.MINOR.PATCH - - All versions with the same MAJOR.MINOR number have the same API ande are ABI compatible. + - All versions with the same MAJOR.MINOR number have the same API and are ABI compatible. ## Running on Linux diff --git a/python/mujinwebstackclient/__init__.py b/python/mujinwebstackclient/__init__.py index 3c0472d..8a45f00 100644 --- a/python/mujinwebstackclient/__init__.py +++ b/python/mujinwebstackclient/__init__.py @@ -4,6 +4,7 @@ from .version import __version__ # noqa: F401 import six +from typing import Optional try: import ujson as json # noqa: F401 @@ -56,16 +57,16 @@ class ClientExceptionBase(Exception): """client base exception""" _message = None # the error message, should be unicode - - def __init__(self, message=''): - if message is not None and not isinstance(message, six.text_type): + + def __init__(self, message: Optional[str]='') -> None: + if message is not None and not isinstance(message, six.text_type): message = message.decode('utf-8', 'ignore') self._message = message - - def __str__(self): - return '%s: %s' % (self.__class__.__name__, self._message) - - def __repr__(self): + + def __str__(self) -> str: + return u'%s: %s' % (self.__class__.__name__, self._message) + + def __repr__(self) -> str: return '<%s(message=%r)>' % (self.__class__.__name__, self._message) @@ -76,8 +77,8 @@ class APIServerError(ClientExceptionBase): _detailInfoType = None # str, the detailed error type given errorcode _detailInfo = None # dcit, the detailed info _inputcommand = None # the command sent to the server - - def __init__(self, message, errorcode=None, inputcommand=None, detailInfoType=None, detailInfo=None): + + def __init__(self, message: str, errorcode: Optional[int]=None, inputcommand: Optional[str]=None, detailInfoType: Optional[str]=None, detailInfo: Optional[dict]=None) -> None: if message is not None and not isinstance(message, six.text_type): message = message.decode('utf-8', 'ignore') self._message = message @@ -85,8 +86,8 @@ def __init__(self, message, errorcode=None, inputcommand=None, detailInfoType=No self._inputcommand = inputcommand self._detailInfoType = detailInfoType self._detailInfo = detailInfo - - def __str__(self): + + def __str__(self) -> str: if self._message is not None: return _('API Server Error: %s') % self._message @@ -96,7 +97,7 @@ def __repr__(self): return '<%s(message=%r, errorcode=%r, inputcommand=%r, detailInfoType=%r, detailInfo=%r)>' % (self.__class__.__name__, self._message, self._errorcode, self._inputcommand, self._detailInfoType, self._detailInfo) @property - def message(self): + def message(self) -> str: """The error message from server.""" return self._message @@ -106,16 +107,17 @@ def errorcode(self): return self._errorcode @property - def stacktrace(self): + def stacktrace(self) -> str: + """The stack trace for the error""" return '' @property - def inputcommand(self): + def inputcommand(self) -> Optional[str]: """The command that was sent to the server. Could be None.""" return self._inputcommand @property - def detailInfoType(self): + def detailInfoType(self) -> Optional[str]: """string for the detai info type""" return self._detailInfoType @@ -134,7 +136,8 @@ class AuthenticationError(ClientExceptionBase): class WebstackClientError(ClientExceptionBase): - _response = None # http response that resulted in the error + """Exeption class for errors returned by the web stack client""" + _response = None # http response that resulted in the error def __init__(self, message='', response=None): super(WebstackClientError, self).__init__(message) @@ -142,6 +145,7 @@ def __init__(self, message='', response=None): @property def response(self): + """The http response that resulted in the error""" return self._response