diff --git a/.pylintrc b/.pylintrc index 67c33d8..965a203 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,9 +7,10 @@ ignore=examples [MESSAGES CONTROL] disable= + multiple-imports, missing-docstring, too-few-public-methods, - dangerous-default-value + dangerous-default-value, [FORMAT] diff --git a/bfxapi/rest/middleware/middleware.py b/bfxapi/rest/middleware/middleware.py index 01f6f60..db98723 100644 --- a/bfxapi/rest/middleware/middleware.py +++ b/bfxapi/rest/middleware/middleware.py @@ -6,7 +6,7 @@ from http import HTTPStatus from ..enums import Error from ..exceptions import ResourceNotFound, RequestParametersError, InvalidAuthenticationCredentials, UnknownGenericError -from ...utils.JSONEncoder import JSONEncoder +from ...utils.json_encoder import JSONEncoder if TYPE_CHECKING: from requests.sessions import _Params diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index 9e3e752..32c2a9b 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from .. labeler import _Type, partial, compose from .. notification import Notification -from .. utils.JSONEncoder import JSON +from ..utils.json_encoder import JSON #region Type hinting for Rest Public Endpoints diff --git a/bfxapi/utils/__init__.py b/bfxapi/utils/__init__.py index 5a6afd1..df6e2da 100644 --- a/bfxapi/utils/__init__.py +++ b/bfxapi/utils/__init__.py @@ -1 +1 @@ -NAME = "utils" \ No newline at end of file +NAME = "utils" diff --git a/bfxapi/utils/camel_and_snake_case_helpers.py b/bfxapi/utils/camel_and_snake_case_helpers.py index 7255940..38a7993 100644 --- a/bfxapi/utils/camel_and_snake_case_helpers.py +++ b/bfxapi/utils/camel_and_snake_case_helpers.py @@ -1,22 +1,23 @@ import re -from typing import TypeVar, Callable, Dict, Any, cast +from typing import TypeVar, Callable, cast T = TypeVar("T") _to_snake_case: Callable[[str], str] = lambda string: re.sub(r"(? T: if isinstance(data, list): return cast(T, [ _scheme(sub_data, adapter) for sub_data in data ]) - elif isinstance(data, dict): + if isinstance(data, dict): return cast(T, { adapter(key): _scheme(value, adapter) for key, value in data.items() }) - else: return data + return data def to_snake_case_keys(dictionary: T) -> T: return _scheme(dictionary, _to_snake_case) def to_camel_case_keys(dictionary: T) -> T: - return _scheme(dictionary, _to_camel_case) \ No newline at end of file + return _scheme(dictionary, _to_camel_case) diff --git a/bfxapi/utils/JSONEncoder.py b/bfxapi/utils/json_encoder.py similarity index 65% rename from bfxapi/utils/JSONEncoder.py rename to bfxapi/utils/json_encoder.py index edaba00..21f0b7e 100644 --- a/bfxapi/utils/JSONEncoder.py +++ b/bfxapi/utils/json_encoder.py @@ -7,23 +7,25 @@ from typing import Type, List, Dict, Union, Any JSON = Union[Dict[str, "JSON"], List["JSON"], bool, int, float, str, Type[None]] def _strip(dictionary: Dict) -> Dict: - return { key: value for key, value in dictionary.items() if value != None} + return { key: value for key, value in dictionary.items() if value is not None } def _convert_float_to_str(data: JSON) -> JSON: if isinstance(data, float): return format(Decimal(repr(data)), "f") - elif isinstance(data, list): + if isinstance(data, list): return [ _convert_float_to_str(sub_data) for sub_data in data ] - elif isinstance(data, dict): + if isinstance(data, dict): return _strip({ key: _convert_float_to_str(value) for key, value in data.items() }) - else: return data + return data class JSONEncoder(json.JSONEncoder): - def encode(self, obj: JSON) -> str: - return json.JSONEncoder.encode(self, _convert_float_to_str(obj)) + def encode(self, o: JSON) -> str: + return json.JSONEncoder.encode(self, _convert_float_to_str(o)) - def default(self, obj: Any) -> Any: - if isinstance(obj, Decimal): return format(obj, "f") - elif isinstance(obj, datetime): return str(obj) + def default(self, o: Any) -> Any: + if isinstance(o, Decimal): + return format(o, "f") + if isinstance(o, datetime): + return str(o) - return json.JSONEncoder.default(self, obj) \ No newline at end of file + return json.JSONEncoder.default(self, o) diff --git a/bfxapi/utils/logger.py b/bfxapi/utils/logger.py index 88d4a59..6ebac5a 100644 --- a/bfxapi/utils/logger.py +++ b/bfxapi/utils/logger.py @@ -28,24 +28,24 @@ class _ColorFormatter(logging.Formatter): class ColorLogger(logging.Logger): FORMAT = "[%(name)s] [%(levelname)s] [%(asctime)s] %(message)s" - + def __init__(self, name, level): - logging.Logger.__init__(self, name, level) + logging.Logger.__init__(self, name, level) colored_formatter = _ColorFormatter(self.FORMAT, use_color=True) - console = logging.StreamHandler(stream=sys.stderr) - console.setFormatter(fmt=colored_formatter) + handler = logging.StreamHandler(stream=sys.stderr) + handler.setFormatter(fmt=colored_formatter) - self.addHandler(hdlr=console) + self.addHandler(hdlr=handler) class FileLogger(logging.Logger): FORMAT = "[%(name)s] [%(levelname)s] [%(asctime)s] %(message)s" - + def __init__(self, name, level, filename): - logging.Logger.__init__(self, name, level) + logging.Logger.__init__(self, name, level) formatter = logging.Formatter(self.FORMAT) - fh = logging.FileHandler(filename=filename) - fh.setFormatter(fmt=formatter) + handler = logging.FileHandler(filename=filename) + handler.setFormatter(fmt=formatter) - self.addHandler(hdlr=fh) \ No newline at end of file + self.addHandler(hdlr=handler) diff --git a/bfxapi/websocket/client/bfx_websocket_client.py b/bfxapi/websocket/client/bfx_websocket_client.py index 11cfa18..ba8843d 100644 --- a/bfxapi/websocket/client/bfx_websocket_client.py +++ b/bfxapi/websocket/client/bfx_websocket_client.py @@ -14,7 +14,7 @@ from .bfx_websocket_inputs import BfxWebsocketInputs from ..handlers import PublicChannelsHandler, AuthenticatedChannelsHandler from ..exceptions import WebsocketAuthenticationRequired, InvalidAuthenticationCredentials, EventNotSupported, OutdatedClientVersion -from ...utils.JSONEncoder import JSONEncoder +from ...utils.json_encoder import JSONEncoder from ...utils.logger import ColorLogger, FileLogger diff --git a/bfxapi/websocket/client/bfx_websocket_inputs.py b/bfxapi/websocket/client/bfx_websocket_inputs.py index 4b4e04c..f3d615f 100644 --- a/bfxapi/websocket/client/bfx_websocket_inputs.py +++ b/bfxapi/websocket/client/bfx_websocket_inputs.py @@ -3,7 +3,7 @@ from datetime import datetime from typing import Union, Optional, List, Tuple from .. enums import OrderType, FundingOfferType -from ... utils.JSONEncoder import JSON +from ...utils.json_encoder import JSON class BfxWebsocketInputs(object): def __init__(self, handle_websocket_input): diff --git a/bfxapi/websocket/types.py b/bfxapi/websocket/types.py index ae082af..8951141 100644 --- a/bfxapi/websocket/types.py +++ b/bfxapi/websocket/types.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from .. labeler import _Type from .. notification import Notification -from .. utils.JSONEncoder import JSON +from ..utils.json_encoder import JSON #region Type hinting for Websocket Public Channels