diff --git a/.pylintrc b/.pylintrc index 7768472..f63ddd0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,12 +9,13 @@ ignore=examples disable= multiple-imports, missing-docstring, + logging-not-lazy, + logging-fstring-interpolation, too-few-public-methods, too-many-public-methods, too-many-instance-attributes, dangerous-default-value, inconsistent-return-statements, - logging-not-lazy [FORMAT] @@ -24,4 +25,4 @@ good-names=id,on,pl,t,ip,tf,A,B,C,D,E,F [TYPECHECK] -generated-members=websockets \ No newline at end of file +generated-members=websockets diff --git a/bfxapi/labeler.py b/bfxapi/labeler.py index cac623a..05dcf8e 100644 --- a/bfxapi/labeler.py +++ b/bfxapi/labeler.py @@ -42,7 +42,7 @@ class _Serializer(Generic[T]): labels = list(filter(lambda label: label not in (skip or []), self.__labels)) if len(labels) > len(args): - raise LabelerSerializerException(f"{self.name} -> and <*args> " + + raise LabelerSerializerException(f"{self.name} -> and <*args> " \ "arguments should contain the same amount of elements.") for index, label in enumerate(labels): diff --git a/bfxapi/rest/middleware/middleware.py b/bfxapi/rest/middleware/middleware.py index 04c0f6c..4bfe8b0 100644 --- a/bfxapi/rest/middleware/middleware.py +++ b/bfxapi/rest/middleware/middleware.py @@ -53,12 +53,12 @@ class Middleware: if len(data) and data[0] == "error": if data[1] == Error.ERR_PARAMS: - raise RequestParametersError("The request was rejected with the " - + f"following parameter error: <{data[2]}>") + raise RequestParametersError("The request was rejected with the " \ + f"following parameter error: <{data[2]}>") if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC: - raise UnknownGenericError("The server replied to the request with " - + f"a generic error with message: <{data[2]}>.") + raise UnknownGenericError("The server replied to the request with " \ + f"a generic error with message: <{data[2]}>.") return data @@ -86,14 +86,14 @@ class Middleware: if isinstance(data, list) and len(data) and data[0] == "error": if data[1] == Error.ERR_PARAMS: - raise RequestParametersError("The request was rejected with the " - + f"following parameter error: <{data[2]}>") + raise RequestParametersError("The request was rejected with the " \ + f"following parameter error: <{data[2]}>") if data[1] == Error.ERR_AUTH_FAIL: raise InvalidAuthenticationCredentials("Cannot authenticate with given API-KEY and API-SECRET.") if data[1] is None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC: - raise UnknownGenericError("The server replied to the request with " - + f"a generic error with message: <{data[2]}>.") + raise UnknownGenericError("The server replied to the request with " \ + f"a generic error with message: <{data[2]}>.") return data diff --git a/bfxapi/tests/test_labeler.py b/bfxapi/tests/test_labeler.py index 5750d9c..04fe2b9 100644 --- a/bfxapi/tests/test_labeler.py +++ b/bfxapi/tests/test_labeler.py @@ -26,8 +26,8 @@ class TestLabeler(unittest.TestCase): msg="_Serializer::get_labels() should return the right list of labels.") with self.assertRaises(LabelerSerializerException, - msg="_Serializer should raise LabelerSerializerException if given " - + "fewer arguments than the serializer labels."): + msg="_Serializer should raise LabelerSerializerException if given " \ + "fewer arguments than the serializer labels."): serializer.parse(5, 65.0, "X") def test_generate_recursive_serializer(self): diff --git a/bfxapi/tests/test_rest_serializers.py b/bfxapi/tests/test_rest_serializers.py index 0cf43b5..c9c1886 100644 --- a/bfxapi/tests/test_rest_serializers.py +++ b/bfxapi/tests/test_rest_serializers.py @@ -10,11 +10,12 @@ class TestRestSerializers(unittest.TestCase): def test_rest_serializers(self): for serializer in map(serializers.__dict__.get, serializers.__serializers__): self.assertTrue(issubclass(serializer.klass, _Type), - f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).") + f"_Serializer <{serializer.name}>: .klass field must be a subclass " \ + f"of _Type (got {serializer.klass}).") self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__), - f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> " - + "must have matching labels and fields.") + f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> " \ + "must have matching labels and fields.") if __name__ == "__main__": unittest.main() diff --git a/bfxapi/tests/test_websocket_serializers.py b/bfxapi/tests/test_websocket_serializers.py index 56708f4..b433868 100644 --- a/bfxapi/tests/test_websocket_serializers.py +++ b/bfxapi/tests/test_websocket_serializers.py @@ -10,11 +10,12 @@ class TestWebsocketSerializers(unittest.TestCase): def test_websocket_serializers(self): for serializer in map(serializers.__dict__.get, serializers.__serializers__): self.assertTrue(issubclass(serializer.klass, _Type), - f"_Serializer <{serializer.name}>: .klass field must be a subclass of _Type (got {serializer.klass}).") + f"_Serializer <{serializer.name}>: .klass field must be a subclass " \ + f"of _Type (got {serializer.klass}).") self.assertListEqual(serializer.get_labels(), list(serializer.klass.__annotations__), - f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> " - + "must have matching labels and fields.") + f"_Serializer <{serializer.name}> and _Type <{serializer.klass.__name__}> " \ + "must have matching labels and fields.") if __name__ == "__main__": unittest.main() diff --git a/bfxapi/websocket/client/bfx_websocket_client.py b/bfxapi/websocket/client/bfx_websocket_client.py index 88cb853..3f893eb 100644 --- a/bfxapi/websocket/client/bfx_websocket_client.py +++ b/bfxapi/websocket/client/bfx_websocket_client.py @@ -22,8 +22,8 @@ from ...utils.logger import ColorLogger, FileLogger def _require_websocket_authentication(function: F) -> F: async def wrapper(self, *args, **kwargs): if hasattr(self, "authentication") and not self.authentication: - raise WebsocketAuthenticationRequired("To perform this action you need to authenticate " + - "using your API_KEY and API_SECRET.") + raise WebsocketAuthenticationRequired("To perform this action you need to " \ + "authenticate using your API_KEY and API_SECRET.") await _require_websocket_connection(function)(self, *args, **kwargs) @@ -86,9 +86,9 @@ class BfxWebsocketClient: async def start(self, connections = 5): if connections > BfxWebsocketClient.MAXIMUM_CONNECTIONS_AMOUNT: - self.logger.warning(f"It is not safe to use more than {BfxWebsocketClient.MAXIMUM_CONNECTIONS_AMOUNT} " - + f"buckets from the same connection ({connections} in use), the server could momentarily " - + "block the client with <429 Too Many Requests>.") + self.logger.warning(f"It is not safe to use more than {BfxWebsocketClient.MAXIMUM_CONNECTIONS_AMOUNT} " \ + f"buckets from the same connection ({connections} in use), the server could momentarily " \ + "block the client with <429 Too Many Requests>.") for _ in range(connections): self.on_open_events.append(asyncio.Event()) @@ -113,9 +113,9 @@ class BfxWebsocketClient: async with websockets.connect(self.host) as websocket: if reconnection.status: - self.logger.info(f"Reconnect attempt successful (attempt no.{reconnection.attempts}): The " - + f"client has been offline for a total of {datetime.now() - reconnection.timestamp} " - + f"(connection lost at: {reconnection.timestamp:%d-%m-%Y at %H:%M:%S}).") + self.logger.info(f"Reconnect attempt successful (attempt no.{reconnection.attempts}): The " \ + f"client has been offline for a total of {datetime.now() - reconnection.timestamp} " \ + f"(connection lost at: {reconnection.timestamp:%d-%m-%Y at %H:%M:%S}).") reconnection = Reconnection(status=False, attempts=0, timestamp=None) @@ -133,9 +133,9 @@ class BfxWebsocketClient: if isinstance(message, dict): if message["event"] == "info" and "version" in message: if BfxWebsocketClient.VERSION != message["version"]: - raise OutdatedClientVersion("Mismatch between the client version and the server " - + "version. Update the library to the latest version to continue (client version: " - + f"{BfxWebsocketClient.VERSION}, server version: {message['version']}).") + raise OutdatedClientVersion("Mismatch between the client version and the server " \ + "version. Update the library to the latest version to continue (client version: " \ + f"{BfxWebsocketClient.VERSION}, server version: {message['version']}).") elif message["event"] == "info" and message["code"] == 20051: rcvd = websockets.frames.Close(code=1012, reason="Stop/Restart Websocket Server (please reconnect).") @@ -165,20 +165,20 @@ class BfxWebsocketClient: except (websockets.ConnectionClosedError, socket.gaierror) as error: if isinstance(error, websockets.ConnectionClosedError) and error.code in (1006, 1012): if error.code == 1006: - self.logger.error("Connection lost: no close frame received " - + "or sent (1006). Attempting to reconnect...") + self.logger.error("Connection lost: no close frame received " \ + "or sent (1006). Attempting to reconnect...") if error.code == 1012: - self.logger.info("WSS server is about to restart, reconnection " - + "required (client received 20051). Attempt in progress...") + self.logger.info("WSS server is about to restart, reconnection " \ + "required (client received 20051). Attempt in progress...") reconnection = Reconnection(status=True, attempts=1, timestamp=datetime.now()) delay = _Delay(backoff_factor=1.618) elif isinstance(error, socket.gaierror) and reconnection.status: - self.logger.warning(f"Reconnection attempt no.{reconnection.attempts} has failed. " - + f"Next reconnection attempt in ~{round(delay.peek()):.1f} seconds. (at the moment " - + f"the client has been offline for {datetime.now() - reconnection.timestamp})") + self.logger.warning(f"Reconnection attempt no.{reconnection.attempts} has failed. " \ + f"Next reconnection attempt in ~{round(delay.peek()):.1f} seconds. (at the moment " \ + f"the client has been offline for {datetime.now() - reconnection.timestamp})") reconnection = reconnection._replace(attempts=reconnection.attempts + 1) else: raise error @@ -231,8 +231,8 @@ class BfxWebsocketClient: def on(self, *events, callback = None): for event in events: if event not in BfxWebsocketClient.EVENTS: - raise EventNotSupported(f"Event <{event}> is not supported. To get a list " - + "of available events print BfxWebsocketClient.EVENTS") + raise EventNotSupported(f"Event <{event}> is not supported. To get a list " \ + "of available events print BfxWebsocketClient.EVENTS") if callback is not None: for event in events: @@ -248,8 +248,8 @@ class BfxWebsocketClient: def once(self, *events, callback = None): for event in events: if event not in BfxWebsocketClient.EVENTS: - raise EventNotSupported(f"Event <{event}> is not supported. To get a list " - + "of available events print BfxWebsocketClient.EVENTS") + raise EventNotSupported(f"Event <{event}> is not supported. To get a list " \ + "of available events print BfxWebsocketClient.EVENTS") if callback is not None: for event in events: