Skip to content

Commit

Permalink
some linting
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone committed Dec 8, 2024
1 parent bcb8dbc commit ff4a6c4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from openbb_websockets.helpers import get_logger, parse_kwargs

connected_clients = set()
connected_clients: set = set()

kwargs = parse_kwargs()

Expand Down
26 changes: 13 additions & 13 deletions openbb_platform/extensions/websockets/openbb_websockets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__( # noqa: PLR0913
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")

Expand Down Expand Up @@ -189,8 +189,8 @@ def _atexit(self) -> None:
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."""
Expand Down Expand Up @@ -372,7 +372,7 @@ def connect(self) -> None:
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}"]),
Expand All @@ -395,10 +395,10 @@ def connect(self) -> None:
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,
Expand All @@ -411,7 +411,7 @@ def connect(self) -> None:
)
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=(
Expand Down Expand Up @@ -564,7 +564,7 @@ def results(self) -> Union[list[dict], list["Data"], None]:

self.logger.info("No results found in %s", self.results_file)

return
return None

@results.deleter
def results(self):
Expand All @@ -588,7 +588,7 @@ def results(self):
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

Expand All @@ -605,7 +605,7 @@ def module(self, module):
]

@property
def symbol(self) -> str:
def symbol(self) -> Union[str, None]:
"""Symbol(s) requested to subscribe."""
return self._symbol

Expand Down Expand Up @@ -683,7 +683,7 @@ def start_broadcasting(
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=(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -247,14 +247,14 @@ def write(self, message):
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):
Expand All @@ -273,7 +273,7 @@ def __init__(self, max_size: int = 1000, max_retries=5, backoff_factor=0.5):
# 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, **kwargs):
self.loop = None
self.websocket = None
self.current_task = None
self.kwargs = {}
self.kwargs: dict = {}
if kwargs:
self.kwargs = kwargs

Expand Down Expand Up @@ -103,18 +103,18 @@ async def listen(self, url, **kwargs): # noqa: PLR0915
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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,19 +1186,20 @@ def __new__(cls, **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):
Expand Down

0 comments on commit ff4a6c4

Please sign in to comment.