From 5543b0b1d2e5e47ad97299666427f504e8747ba9 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Tue, 27 Feb 2024 17:24:47 +0100 Subject: [PATCH] Fix all flake8 errors in all python files (+ edit configuration files). --- .flake8 | 6 +++++ bfxapi/_utils/json_decoder.py | 2 +- bfxapi/_utils/logging.py | 3 +-- .../rest/endpoints/rest_merchant_endpoints.py | 6 +++-- bfxapi/types/labeler.py | 3 ++- bfxapi/types/serializers.py | 6 ++--- .../websocket/_client/bfx_websocket_bucket.py | 4 +-- .../websocket/_client/bfx_websocket_client.py | 24 ++++++++++-------- .../_event_emitter/bfx_event_emitter.py | 4 +-- dev-requirements.txt | Bin 380 -> 326 bytes pyproject.toml | 7 ----- 11 files changed, 33 insertions(+), 32 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..4483e68 --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] +max-line-length = 88 +extend-select = B950 +extend-ignore = E203,E501,E701 + +per-file-ignores = */__init__.py:F401 diff --git a/bfxapi/_utils/json_decoder.py b/bfxapi/_utils/json_decoder.py index 21164a9..3597de9 100644 --- a/bfxapi/_utils/json_decoder.py +++ b/bfxapi/_utils/json_decoder.py @@ -13,4 +13,4 @@ def _object_hook(data: Dict[str, Any]) -> Any: class JSONDecoder(json.JSONDecoder): def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(object_hook=_object_hook, *args, **kwargs) + super().__init__(*args, **kwargs, object_hook=_object_hook) diff --git a/bfxapi/_utils/logging.py b/bfxapi/_utils/logging.py index e19a120..9eca09c 100644 --- a/bfxapi/_utils/logging.py +++ b/bfxapi/_utils/logging.py @@ -1,7 +1,6 @@ import sys from copy import copy - -from logging import * +from logging import FileHandler, Formatter, Logger, LogRecord, StreamHandler from typing import TYPE_CHECKING, Literal, Optional if TYPE_CHECKING: diff --git a/bfxapi/rest/endpoints/rest_merchant_endpoints.py b/bfxapi/rest/endpoints/rest_merchant_endpoints.py index 6f783d6..3c4d9af 100644 --- a/bfxapi/rest/endpoints/rest_merchant_endpoints.py +++ b/bfxapi/rest/endpoints/rest_merchant_endpoints.py @@ -178,8 +178,10 @@ class RestMerchantEndpoints(Middleware): def get_merchant_settings(self, key: str) -> Any: return self._post("auth/r/ext/pay/settings/get", body={"key": key}) - def list_merchant_settings(self, keys: List[str] = []) -> Dict[str, Any]: - return self._post("auth/r/ext/pay/settings/list", body={"keys": keys}) + def list_merchant_settings( + self, keys: Optional[List[str]] = None + ) -> Dict[str, Any]: + return self._post("auth/r/ext/pay/settings/list", body={"keys": keys or []}) def get_deposits( self, diff --git a/bfxapi/types/labeler.py b/bfxapi/types/labeler.py index 008a07d..6c2e373 100644 --- a/bfxapi/types/labeler.py +++ b/bfxapi/types/labeler.py @@ -24,7 +24,8 @@ def partial(cls): if len(kwargs) != 0: raise TypeError( - f"{cls.__name__}.__init__() got an unexpected keyword argument '{list(kwargs.keys())[0]}'" + f"{cls.__name__}.__init__() got an unexpected " + "keyword argument '{list(kwargs.keys())[0]}'" ) cls.__init__ = __init__ diff --git a/bfxapi/types/serializers.py b/bfxapi/types/serializers.py index d5d2dab..ae2b3b1 100644 --- a/bfxapi/types/serializers.py +++ b/bfxapi/types/serializers.py @@ -1,12 +1,10 @@ from . import dataclasses - -from .labeler import ( +from .labeler import ( # noqa: F401 _Serializer, generate_labeler_serializer, generate_recursive_serializer, ) - -from .notification import _Notification +from .notification import _Notification # noqa: F401 __serializers__ = [ "PlatformStatus", diff --git a/bfxapi/websocket/_client/bfx_websocket_bucket.py b/bfxapi/websocket/_client/bfx_websocket_bucket.py index 5980440..fa6262f 100644 --- a/bfxapi/websocket/_client/bfx_websocket_bucket.py +++ b/bfxapi/websocket/_client/bfx_websocket_bucket.py @@ -15,7 +15,7 @@ _CHECKSUM_FLAG_VALUE = 131_072 def _strip(message: Dict[str, Any], keys: List[str]) -> Dict[str, Any]: - return {key: value for key, value in message.items() if not key in keys} + return {key: value for key, value in message.items() if key not in keys} class BfxWebSocketBucket(Connection): @@ -136,7 +136,7 @@ class BfxWebSocketBucket(Connection): await self.subscribe(**subscription) @Connection._require_websocket_connection - async def close(self, code: int = 1000, reason: str = str()) -> None: + async def close(self, code: int = 1000, reason: str = "") -> None: await self._websocket.close(code, reason) def has(self, sub_id: str) -> bool: diff --git a/bfxapi/websocket/_client/bfx_websocket_client.py b/bfxapi/websocket/_client/bfx_websocket_client.py index a1a2cb2..ffae0ad 100644 --- a/bfxapi/websocket/_client/bfx_websocket_client.py +++ b/bfxapi/websocket/_client/bfx_websocket_client.py @@ -100,7 +100,7 @@ class BfxWebSocketClient(Connection): type(exception), exception, exception.__traceback__ ) - self.__logger.critical(header + "\n" + str().join(stack_trace)[:-1]) + self.__logger.critical(f"{header}\n" + str().join(stack_trace)[:-1]) @property def inputs(self) -> BfxWebSocketInputs: @@ -141,6 +141,8 @@ class BfxWebSocketClient(Connection): try: await task except (ConnectionClosedError, InvalidStatusCode, gaierror) as _e: + nonlocal error + if type(error) is not type(_e) or error.args != _e.args: raise _e except asyncio.CancelledError: @@ -241,8 +243,9 @@ class BfxWebSocketClient(Connection): if message["version"] != 2: raise VersionMismatchError( "Mismatch between the client and the server version: " - + "please update bitfinex-api-py to the latest version to resolve this error " - + f"(client version: 2, server version: {message['version']})." + "please update bitfinex-api-py to the latest version " + f"to resolve this error (client version: 2, server " + f"version: {message['version']})." ) elif message["event"] == "info" and message["code"] == 20051: rcvd = websockets.frames.Close( @@ -253,8 +256,7 @@ class BfxWebSocketClient(Connection): elif message["event"] == "auth": if message["status"] != "OK": raise InvalidCredentialError( - "Can't authenticate " - + "with given API-KEY and API-SECRET." + "Can't authenticate with given API-KEY and API-SECRET." ) self.__event_emitter.emit("authenticated", message) @@ -281,14 +283,14 @@ class BfxWebSocketClient(Connection): async def subscribe( self, channel: str, sub_id: Optional[str] = None, **kwargs: Any ) -> None: - if not channel in ["ticker", "trades", "book", "candles", "status"]: + if channel not in ["ticker", "trades", "book", "candles", "status"]: raise UnknownChannelError( - "Available channels are: " + "ticker, trades, book, candles and status." + "Available channels are: ticker, trades, book, candles and status." ) for bucket in self.__buckets: if sub_id in bucket.ids: - raise SubIdError("sub_id must be " + "unique for all subscriptions.") + raise SubIdError("sub_id must be unique for all subscriptions.") for bucket in self.__buckets: if not bucket.is_full: @@ -310,7 +312,7 @@ class BfxWebSocketClient(Connection): return await bucket.unsubscribe(sub_id) raise UnknownSubscriptionError( - "Unable to find " + f"a subscription with sub_id <{sub_id}>." + f"Unable to find a subscription with sub_id <{sub_id}>." ) @Connection._require_websocket_connection @@ -320,11 +322,11 @@ class BfxWebSocketClient(Connection): return await bucket.resubscribe(sub_id) raise UnknownSubscriptionError( - "Unable to find " + f"a subscription with sub_id <{sub_id}>." + f"Unable to find a subscription with sub_id <{sub_id}>." ) @Connection._require_websocket_connection - async def close(self, code: int = 1000, reason: str = str()) -> None: + async def close(self, code: int = 1000, reason: str = "") -> None: for bucket in self.__buckets: await bucket.close(code=code, reason=reason) diff --git a/bfxapi/websocket/_event_emitter/bfx_event_emitter.py b/bfxapi/websocket/_event_emitter/bfx_event_emitter.py index 89931ba..3638767 100644 --- a/bfxapi/websocket/_event_emitter/bfx_event_emitter.py +++ b/bfxapi/websocket/_event_emitter/bfx_event_emitter.py @@ -105,8 +105,8 @@ class BfxEventEmitter(AsyncIOEventEmitter): ) -> Union[_Handler, Callable[[_Handler], _Handler]]: if event not in BfxEventEmitter._EVENTS: raise UnknownEventError( - f"Can't register to unknown event: <{event}> " - + "(to get a full list of available events see https://docs.bitfinex.com/)." + f"Can't register to unknown event: <{event}> (to get a full" + "list of available events see https://docs.bitfinex.com/)." ) return super().on(event, f) diff --git a/dev-requirements.txt b/dev-requirements.txt index b0c0355be5d804c2fd7be167c3f83556ee67034d..a902e7091035fcd1f62914bc8db4e97b1b6e4b85 100644 GIT binary patch delta 24 gcmeyvbc|`jwTZXnCQC8$Oy*z|n)pLtvKpfb0DYYZl>h($ delta 57 zcmX@c^oMD}wTYLMCVo(wEXHU6#C$3R43!K83`Gq23|S1R49N^747NaM$e_ny1jNP+ IybN3n01bQ%ZU6uP diff --git a/pyproject.toml b/pyproject.toml index db770cc..6163d4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,10 +3,3 @@ profile = "black" [tool.black] target-version = ["py38", "py39", "py310", "py311"] - -preview = true - -[tool.flake8] -max-line-length = 88 -extend-select = "B950" -extend-ignore = ["E203", "E501", "E701"]