mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 23:41:27 +00:00
some linting
This commit is contained in:
@@ -10,7 +10,7 @@ from starlette.websockets import WebSocketState
|
||||
|
||||
from openbb_websockets.helpers import get_logger, parse_kwargs
|
||||
|
||||
connected_clients = set()
|
||||
connected_clients: set = set()
|
||||
|
||||
kwargs = parse_kwargs()
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ class WebSocketClient:
|
||||
self.results_path = Path(temp_file_path).absolute()
|
||||
self.results_file = temp_file_path
|
||||
|
||||
self.results_path = Path(self.results_file).absolute()
|
||||
self.results_path = Path(self.results_file).absolute() # type: ignore
|
||||
self.save_results = save_results
|
||||
self.logger = logger if logger else get_logger("openbb.websocket.client")
|
||||
|
||||
@@ -189,8 +189,8 @@ class WebSocketClient:
|
||||
self.stop_broadcasting()
|
||||
if self.save_results:
|
||||
self.logger.info("Websocket results saved to, %s\n", str(self.results_path))
|
||||
if os.path.exists(self.results_file) and not self.save_results:
|
||||
os.remove(self.results_file)
|
||||
if os.path.exists(self.results_file) and not self.save_results: # type: ignore
|
||||
os.remove(self.results_file) # type: ignore
|
||||
|
||||
def _setup_database(self) -> None:
|
||||
"""Set up the SQLite database and table."""
|
||||
@@ -372,7 +372,7 @@ class WebSocketClient:
|
||||
self.logger.info("No subscribed symbols.")
|
||||
return
|
||||
|
||||
command = self.module.copy()
|
||||
command = self.module
|
||||
command.extend([f"symbol={symbol}"])
|
||||
command.extend([f"results_file={self.results_file}"])
|
||||
command.extend([f"table_name={self.table_name}"]),
|
||||
@@ -395,10 +395,10 @@ class WebSocketClient:
|
||||
if kwargs
|
||||
else None
|
||||
)
|
||||
|
||||
for kwarg in _kwargs:
|
||||
if kwarg not in command:
|
||||
command.extend([kwarg])
|
||||
if _kwargs is not None:
|
||||
for kwarg in _kwargs:
|
||||
if kwarg not in command:
|
||||
command.extend([kwarg])
|
||||
|
||||
self._process = subprocess.Popen( # noqa
|
||||
command,
|
||||
@@ -411,7 +411,7 @@ class WebSocketClient:
|
||||
)
|
||||
self._psutil_process = psutil.Process(self._process.pid)
|
||||
|
||||
log_output_queue = queue.Queue()
|
||||
log_output_queue: queue.Queue = queue.Queue()
|
||||
self._thread = threading.Thread(
|
||||
target=non_blocking_websocket,
|
||||
args=(
|
||||
@@ -564,7 +564,7 @@ class WebSocketClient:
|
||||
|
||||
self.logger.info("No results found in %s", self.results_file)
|
||||
|
||||
return
|
||||
return None
|
||||
|
||||
@results.deleter
|
||||
def results(self):
|
||||
@@ -588,7 +588,7 @@ class WebSocketClient:
|
||||
self.logger.error("Error clearing results: %s", e)
|
||||
|
||||
@property
|
||||
def module(self) -> str:
|
||||
def module(self) -> list:
|
||||
"""Path to the provider connection script."""
|
||||
return self._module
|
||||
|
||||
@@ -605,7 +605,7 @@ class WebSocketClient:
|
||||
]
|
||||
|
||||
@property
|
||||
def symbol(self) -> str:
|
||||
def symbol(self) -> Union[str, None]:
|
||||
"""Symbol(s) requested to subscribe."""
|
||||
return self._symbol
|
||||
|
||||
@@ -683,7 +683,7 @@ class WebSocketClient:
|
||||
bufsize=1,
|
||||
)
|
||||
self._psutil_broadcast_process = psutil.Process(self._broadcast_process.pid)
|
||||
output_queue = queue.Queue()
|
||||
output_queue: queue.Queue = queue.Queue()
|
||||
self._broadcast_thread = threading.Thread(
|
||||
target=non_blocking_broadcast,
|
||||
args=(
|
||||
|
||||
@@ -153,7 +153,7 @@ def parse_kwargs():
|
||||
value = args[i + 1]
|
||||
|
||||
if isinstance(value, str) and value.lower() in ["false", "true"]:
|
||||
value = value.lower() == "true"
|
||||
value = value.lower() == "true" # type: ignore
|
||||
elif isinstance(value, str) and value.lower() == "none":
|
||||
value = None
|
||||
_kwargs[key] = value
|
||||
@@ -247,14 +247,14 @@ class StdOutSink:
|
||||
cleaned_message = AUTH_TOKEN_FILTER.sub(r"\1********", message)
|
||||
if cleaned_message != message:
|
||||
cleaned_message = f"{cleaned_message}\n"
|
||||
sys.__stdout__.write(cleaned_message)
|
||||
sys.__stdout__.write(cleaned_message) # type: ignore
|
||||
|
||||
def flush(self):
|
||||
"""Flush stdout."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import sys
|
||||
|
||||
sys.__stdout__.flush()
|
||||
sys.__stdout__.flush() # type: ignore
|
||||
|
||||
|
||||
class AuthTokenFilter(logging.Formatter):
|
||||
@@ -273,7 +273,7 @@ class MessageQueue:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from asyncio import Queue
|
||||
|
||||
self.queue = Queue(maxsize=max_size)
|
||||
self.queue: Queue = Queue(maxsize=max_size)
|
||||
self.max_retries = max_retries
|
||||
self.backoff_factor = backoff_factor
|
||||
self.logger = get_logger("openbb.websocket.queue")
|
||||
|
||||
@@ -10,7 +10,7 @@ class Listener:
|
||||
self.loop = None
|
||||
self.websocket = None
|
||||
self.current_task = None
|
||||
self.kwargs = {}
|
||||
self.kwargs: dict = {}
|
||||
if kwargs:
|
||||
self.kwargs = kwargs
|
||||
|
||||
@@ -103,18 +103,18 @@ class Listener:
|
||||
def stop(self):
|
||||
if self.current_task:
|
||||
self.current_task.cancel()
|
||||
self.loop.run_until_complete(self.current_task)
|
||||
self.loop.run_until_complete(self.current_task) # type: ignore
|
||||
if self.websocket:
|
||||
self.loop.run_until_complete(self.websocket.close())
|
||||
if not self.loop.is_closed():
|
||||
self.loop.stop()
|
||||
self.loop.run_until_complete(self.websocket.close()) # type: ignore
|
||||
if not self.loop.is_closed(): # type: ignore
|
||||
self.loop.stop() # type: ignore
|
||||
|
||||
async def start_listening(self, url, **kwargs):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import asyncio
|
||||
import contextlib
|
||||
|
||||
self.current_task = self.loop.create_task(self.listen(url, **kwargs))
|
||||
self.current_task = self.loop.create_task(self.listen(url, **kwargs)) # type: ignore
|
||||
with contextlib.suppress(asyncio.CancelledError):
|
||||
await self.current_task
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Intrinio Realtime Stocks Client."""
|
||||
|
||||
# pylint: disable
|
||||
# pylint: skip-file
|
||||
# flake8: noqa
|
||||
# This file is a slightly modified version of the original file from the Intrinio Python SDK.
|
||||
|
||||
|
||||
@@ -1186,19 +1186,20 @@ class PolygonWebSocketData(Data):
|
||||
).startswith("O:")
|
||||
|
||||
if options_symbol:
|
||||
model = OPTIONS_MODEL_MAP.get(data.get("ev")) or OPTIONS_MODEL_MAP.get(
|
||||
data.get("type")
|
||||
model = OPTIONS_MODEL_MAP.get(data.get("ev", "")) or OPTIONS_MODEL_MAP.get(
|
||||
data.get("type", "")
|
||||
)
|
||||
else:
|
||||
model = (
|
||||
MODEL_MAP["A"]
|
||||
if index_symbol
|
||||
else MODEL_MAP.get(data.get("ev")) or MODEL_MAP.get(data.get("type"))
|
||||
else MODEL_MAP.get(data.get("ev", ""))
|
||||
or MODEL_MAP.get(data.get("type", ""))
|
||||
)
|
||||
if not model:
|
||||
return super().__new__(cls)
|
||||
|
||||
return model.model_validate(data)
|
||||
return model.model_validate(data) # type: ignore
|
||||
|
||||
|
||||
class PolygonWebSocketConnection(WebSocketConnection):
|
||||
|
||||
Reference in New Issue
Block a user