Skip to content

Commit f6a2464

Browse files
authored
Use ABC instead of Protocol (#12)
1 parent 471dd8d commit f6a2464

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

publisher/provider.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from abc import ABC, abstractmethod
2+
import asyncio
13
from dataclasses import dataclass
2-
from typing import List, Optional, Protocol
4+
from typing import List, Optional
35

46
Symbol = str
57

@@ -10,12 +12,18 @@ class Price:
1012
conf: float
1113

1214

13-
class Provider(Protocol):
15+
class Provider(ABC):
16+
@abstractmethod
1417
def upd_products(self, product_symbols: List[Symbol]):
1518
...
1619

17-
def start(self):
20+
def start(self) -> None:
21+
asyncio.create_task(self._update_loop())
22+
23+
@abstractmethod
24+
async def _update_loop(self):
1825
...
1926

27+
@abstractmethod
2028
def latest_price(self, symbol: Symbol) -> Optional[Price]:
2129
...

publisher/providers/coin_gecko.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ def __init__(self, config: CoinGeckoConfig) -> None:
2222
}
2323
self._config = config
2424

25-
def start(self) -> None:
26-
asyncio.create_task(self._update_loop())
27-
2825
def upd_products(self, product_symbols: List[Symbol]) -> None:
2926
new_prices = {}
3027
for coin_gecko_product in self._config.products:

publisher/providers/pyth_replicator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def __init__(self, config: PythReplicatorConfig) -> None:
2929
str, Tuple[float | None, float | None, UnixTimestamp | None]
3030
] = {}
3131

32-
def start(self) -> None:
33-
asyncio.create_task(self._ws_loop())
34-
35-
async def _ws_loop(self) -> None:
32+
async def _update_loop(self) -> None:
3633
self._ws = self._client.create_watch_session()
3734
log.info("Creating Pyth replicator WS")
3835

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="example-publisher",
5-
version="0.1.0",
5+
version="0.1.1",
66
author="Pyth Data Association",
77
author_email="",
88
packages=find_packages(exclude=["tests"]),

0 commit comments

Comments
 (0)