Skip to content

Commit

Permalink
fix(observer): fix pyright errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasbadadare committed Nov 13, 2024
1 parent d39685c commit 7e34307
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
12 changes: 8 additions & 4 deletions pyth_observer/check/price_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ class PriceFeedState:

@runtime_checkable
class PriceFeedCheck(Protocol):
def __init__(self, state: PriceFeedState, config: PriceFeedCheckConfig): ...
def __init__(self, state: PriceFeedState, config: PriceFeedCheckConfig):
...

def state(self) -> PriceFeedState: ...
def state(self) -> PriceFeedState:
...

def run(self) -> bool: ...
def run(self) -> bool:
...

def error_message(self) -> dict: ...
def error_message(self) -> dict:
...


class PriceFeedOfflineCheck(PriceFeedCheck):
Expand Down
26 changes: 12 additions & 14 deletions pyth_observer/check/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class PriceUpdate:
PUBLISHER_CACHE_MAX_LEN = 30
"""Roughly 30 mins of updates, since the check runs about once a minute"""

PUBLISHER_CACHE: Dict[tuple[str, str], List[PriceUpdate]] = defaultdict(
lambda: deque(maxlen=PUBLISHER_CACHE_MAX_LEN)
)
PUBLISHER_CACHE = defaultdict(lambda: deque(maxlen=PUBLISHER_CACHE_MAX_LEN))
"""
Cache that holds tuples of (price, timestamp) for publisher/feed combos as they stream in.
Entries longer than `PUBLISHER_CACHE_MAX_LEN` are automatically pruned.
Expand Down Expand Up @@ -54,13 +52,17 @@ class PublisherState:

@runtime_checkable
class PublisherCheck(Protocol):
def __init__(self, state: PublisherState, config: PublisherCheckConfig): ...
def __init__(self, state: PublisherState, config: PublisherCheckConfig):
...

def state(self) -> PublisherState: ...
def state(self) -> PublisherState:
...

def run(self) -> bool: ...
def run(self) -> bool:
...

def error_message(self) -> dict: ...
def error_message(self) -> dict:
...


class PublisherWithinAggregateConfidenceCheck(PublisherCheck):
Expand Down Expand Up @@ -256,19 +258,15 @@ def __init__(self, state: PublisherState, config: PublisherCheckConfig):
self.__max_slot_distance: int = int(config["max_slot_distance"])

from pyth_observer.check.stall_detection import (
StallDetectionResult,
StallDetector,
) # noqa: deferred import to avoid circular import

self.__detector = StallDetector(
stall_time_limit=self.__stall_time_limit,
noise_threshold=float(config.get("noise_threshold")),
min_noise_samples=int(config.get("min_noise_samples")),
noise_threshold=float(config["noise_threshold"]),
min_noise_samples=int(config["min_noise_samples"]),
)

# Keep track of last analysis for error reporting
self.__last_analysis: Optional[StallDetectionResult] = None

def state(self) -> PublisherState:
return self.__state

Expand Down Expand Up @@ -297,7 +295,7 @@ def run(self) -> bool:
publisher_key = (self.__state.publisher_name, self.__state.symbol)
PUBLISHER_CACHE[publisher_key].append(
PriceUpdate(current_time, self.__state.price)
),
)
updates = PUBLISHER_CACHE[publisher_key]

# Analyze for stalls
Expand Down
10 changes: 5 additions & 5 deletions pyth_observer/check/stall_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ def analyze_updates(self, updates: List[PriceUpdate]) -> StallDetectionResult:
return StallDetectionResult(
is_stalled=True,
stall_type="noisy",
base_price=base_price,
noise_magnitude=max_relative_deviation * base_price,
base_price=float(base_price),
noise_magnitude=float(max_relative_deviation * base_price),
duration=duration,
confidence=confidence,
confidence=float(confidence),
)

return StallDetectionResult(
is_stalled=False,
stall_type=None,
base_price=base_price,
noise_magnitude=max_relative_deviation * base_price,
base_price=float(base_price),
noise_magnitude=float(max_relative_deviation * base_price),
duration=duration,
confidence=0.0,
)
1 change: 0 additions & 1 deletion pyth_observer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def run(config, publishers, coingecko_mapping, prometheus_port):
logger.remove()
logger.add(
sys.stdout,
colorize=(os.environ.get("DEV_MODE")),
serialize=(not os.environ.get("DEV_MODE")),
level=os.environ.get("LOG_LEVEL", "INFO"),
)
3 changes: 2 additions & 1 deletion pyth_observer/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Event(Protocol):
check: Check
context: Context

async def send(self): ...
async def send(self):
...


class DatadogEvent(Event):
Expand Down
1 change: 0 additions & 1 deletion tests/test_checks_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import time
from unittest.mock import patch

import numpy as np
import pytest
from pythclient.pythaccounts import PythPriceStatus
from pythclient.solana import SolanaPublicKey
Expand Down

0 comments on commit 7e34307

Please sign in to comment.