Skip to content

Commit 7e34307

Browse files
committed
fix(observer): fix pyright errors
1 parent d39685c commit 7e34307

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

pyth_observer/check/price_feed.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ class PriceFeedState:
3232

3333
@runtime_checkable
3434
class PriceFeedCheck(Protocol):
35-
def __init__(self, state: PriceFeedState, config: PriceFeedCheckConfig): ...
35+
def __init__(self, state: PriceFeedState, config: PriceFeedCheckConfig):
36+
...
3637

37-
def state(self) -> PriceFeedState: ...
38+
def state(self) -> PriceFeedState:
39+
...
3840

39-
def run(self) -> bool: ...
41+
def run(self) -> bool:
42+
...
4043

41-
def error_message(self) -> dict: ...
44+
def error_message(self) -> dict:
45+
...
4246

4347

4448
class PriceFeedOfflineCheck(PriceFeedCheck):

pyth_observer/check/publisher.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class PriceUpdate:
2222
PUBLISHER_CACHE_MAX_LEN = 30
2323
"""Roughly 30 mins of updates, since the check runs about once a minute"""
2424

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

5553
@runtime_checkable
5654
class PublisherCheck(Protocol):
57-
def __init__(self, state: PublisherState, config: PublisherCheckConfig): ...
55+
def __init__(self, state: PublisherState, config: PublisherCheckConfig):
56+
...
5857

59-
def state(self) -> PublisherState: ...
58+
def state(self) -> PublisherState:
59+
...
6060

61-
def run(self) -> bool: ...
61+
def run(self) -> bool:
62+
...
6263

63-
def error_message(self) -> dict: ...
64+
def error_message(self) -> dict:
65+
...
6466

6567

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

258260
from pyth_observer.check.stall_detection import (
259-
StallDetectionResult,
260261
StallDetector,
261262
) # noqa: deferred import to avoid circular import
262263

263264
self.__detector = StallDetector(
264265
stall_time_limit=self.__stall_time_limit,
265-
noise_threshold=float(config.get("noise_threshold")),
266-
min_noise_samples=int(config.get("min_noise_samples")),
266+
noise_threshold=float(config["noise_threshold"]),
267+
min_noise_samples=int(config["min_noise_samples"]),
267268
)
268269

269-
# Keep track of last analysis for error reporting
270-
self.__last_analysis: Optional[StallDetectionResult] = None
271-
272270
def state(self) -> PublisherState:
273271
return self.__state
274272

@@ -297,7 +295,7 @@ def run(self) -> bool:
297295
publisher_key = (self.__state.publisher_name, self.__state.symbol)
298296
PUBLISHER_CACHE[publisher_key].append(
299297
PriceUpdate(current_time, self.__state.price)
300-
),
298+
)
301299
updates = PUBLISHER_CACHE[publisher_key]
302300

303301
# Analyze for stalls

pyth_observer/check/stall_detection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ def analyze_updates(self, updates: List[PriceUpdate]) -> StallDetectionResult:
133133
return StallDetectionResult(
134134
is_stalled=True,
135135
stall_type="noisy",
136-
base_price=base_price,
137-
noise_magnitude=max_relative_deviation * base_price,
136+
base_price=float(base_price),
137+
noise_magnitude=float(max_relative_deviation * base_price),
138138
duration=duration,
139-
confidence=confidence,
139+
confidence=float(confidence),
140140
)
141141

142142
return StallDetectionResult(
143143
is_stalled=False,
144144
stall_type=None,
145-
base_price=base_price,
146-
noise_magnitude=max_relative_deviation * base_price,
145+
base_price=float(base_price),
146+
noise_magnitude=float(max_relative_deviation * base_price),
147147
duration=duration,
148148
confidence=0.0,
149149
)

pyth_observer/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def run(config, publishers, coingecko_mapping, prometheus_port):
6767
logger.remove()
6868
logger.add(
6969
sys.stdout,
70-
colorize=(os.environ.get("DEV_MODE")),
7170
serialize=(not os.environ.get("DEV_MODE")),
7271
level=os.environ.get("LOG_LEVEL", "INFO"),
7372
)

pyth_observer/event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Event(Protocol):
2727
check: Check
2828
context: Context
2929

30-
async def send(self): ...
30+
async def send(self):
31+
...
3132

3233

3334
class DatadogEvent(Event):

tests/test_checks_publisher.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import time
33
from unittest.mock import patch
44

5-
import numpy as np
65
import pytest
76
from pythclient.pythaccounts import PythPriceStatus
87
from pythclient.solana import SolanaPublicKey

0 commit comments

Comments
 (0)