Skip to content

Commit 657ee47

Browse files
author
Andrew Brookins
committed
Better type annotations
1 parent 93bc4c7 commit 657ee47

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

app/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import logging
33
from datetime import datetime
4+
from typing import Any
45
from typing import Dict
56
from typing import Iterable
67
from typing import List
@@ -21,16 +22,20 @@
2122
TIME_FORMAT_STRING = '%Y-%m-%d_%H'
2223
TWO_MINUTES = 60 * 60
2324

25+
BitcoinSentiments = List[Dict[str, Union[str, float]]]
26+
2427

2528
def prefixed_key(f):
2629
"""
2730
A method decorator that prefixes return values.
31+
2832
Prefixes any string that the decorated method `f` returns with the value of
2933
the `prefix` attribute on the owner object `self`.
3034
"""
3135

32-
def prefixed_method(self, *args, **kwargs):
33-
key = f(self, *args, **kwargs)
36+
def prefixed_method(*args, **kwargs):
37+
self = args[0]
38+
key = f(*args, **kwargs)
3439
return f'{self.prefix}:{key}'
3540

3641
return prefixed_method
@@ -56,6 +61,7 @@ def summary_key(self) -> str:
5661

5762

5863
class Config(BaseSettings):
64+
# The default URL expects the app to run using Docker and docker-compose.
5965
redis_url: str = 'redis://redis:6379'
6066

6167

@@ -81,7 +87,7 @@ def make_summary(data):
8187

8288
async def add_many_to_timeseries(
8389
key_pairs: Iterable[Tuple[str, str]],
84-
data: List[Dict[str, Union[str, float]]]
90+
data: BitcoinSentiments
8591
):
8692
"""
8793
Add many samples to a single timeseries key.
@@ -103,7 +109,7 @@ def make_keys():
103109
return Keys()
104110

105111

106-
async def persist(keys, data, summary):
112+
async def persist(keys: Keys, data: BitcoinSentiments, summary: Dict[str, Any]):
107113
# TODO: Only add timeseries data that we don't already have -- how?
108114
ts_price_key = keys.timeseries_price_key()
109115
ts_sentiment_key = keys.timeseries_sentiment_key()

0 commit comments

Comments
 (0)