Skip to content

Commit 786bb58

Browse files
authored
Added type annotation to some functions to make the code more readable. (#51)
1 parent fdc3432 commit 786bb58

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

pythclient/config.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Library-wide settings.
33
"""
44

5-
backoff_max_value = 16
6-
backoff_max_tries = 8
5+
BACKOFF_MAX_VALUE = 16
6+
BACKOFF_MAX_TRIES = 8
77

88
# The following getter functions are passed to the backoff decorators
99

10-
def get_backoff_max_value():
11-
return backoff_max_value
10+
def get_backoff_max_value() -> int:
11+
return BACKOFF_MAX_VALUE
1212

13-
def get_backoff_max_tries():
14-
return backoff_max_tries
13+
def get_backoff_max_tries() -> int:
14+
return BACKOFF_MAX_TRIES

pythclient/price_feeds.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class Price:
22-
def __init__(self, conf, expo, price, publish_time):
22+
def __init__(self, conf, expo, price, publish_time) -> None:
2323
self.conf = conf
2424
self.expo = expo
2525
self.price = price
@@ -38,7 +38,7 @@ def to_dict(self):
3838

3939

4040
class PriceUpdate:
41-
def __init__(self, ema_price, price_id, price):
41+
def __init__(self, ema_price, price_id, price) -> None:
4242
self.ema_price = ema_price
4343
self.id = price_id
4444
self.price = price
@@ -66,7 +66,7 @@ def __init__(
6666
last_attested_publish_time,
6767
price_feed,
6868
emitter_chain_id,
69-
):
69+
) -> None:
7070
self.seq_num = seq_num
7171
self.vaa = vaa
7272
self.publish_time = publish_time
@@ -117,7 +117,7 @@ def to_dict(self, verbose=False, vaa_format=DEFAULT_VAA_ENCODING):
117117
class MerkleUpdate:
118118
def __init__(
119119
self, message_size: int, message: bytes, proof_size: int, proof: List[bytes]
120-
):
120+
) -> None:
121121
self.message_size = message_size
122122
self.message = message
123123
self.proof_size = proof_size
@@ -142,7 +142,7 @@ def __init__(
142142
vaa: bytes,
143143
num_updates: int,
144144
updates: List[MerkleUpdate],
145-
):
145+
) -> None:
146146
self.magic = magic
147147
self.major_version = major_version
148148
self.minor_version = minor_version
@@ -195,7 +195,7 @@ def encode_vaa_for_chain(vaa: str, vaa_format: str, buffer=False) -> Union[bytes
195195

196196

197197
# Referenced from https://github.com/wormhole-foundation/wormhole/blob/main/sdk/js/src/vaa/wormhole.ts#L26-L56
198-
def parse_vaa(vaa, encoding):
198+
def parse_vaa(vaa: str, encoding: str) -> dict:
199199
vaa = cast(bytes, encode_vaa_for_chain(vaa, encoding, buffer=True))
200200

201201
num_signers = vaa[5]

pythclient/pythaccounts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _read_attribute_string(buffer: bytes, offset: int) -> Tuple[Optional[str], i
7878
return data.decode('utf8', 'replace'), data_end
7979

8080

81-
def _parse_header(buffer: bytes, offset: int = 0, *, key: SolanaPublicKeyOrStr):
81+
def _parse_header(buffer: bytes, offset: int = 0, *, key: SolanaPublicKeyOrStr) -> Tuple[PythAccountType, int, int]:
8282
if len(buffer) - offset < _ACCOUNT_HEADER_BYTES:
8383
raise ValueError("Pyth account data too short")
8484

0 commit comments

Comments
 (0)