Skip to content

Commit 669b301

Browse files
committed
Added Python type annotations
1 parent 4cf88ea commit 669b301

File tree

23 files changed

+72
-58
lines changed

23 files changed

+72
-58
lines changed

awesome/parse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def parse_header(s: str) -> tuple[int, str]:
132132
return level, name
133133

134134

135-
def check_items_sorted(data: dict):
135+
def ensure_items_sorted(data: dict) -> None:
136136
prev_name = ''
137137

138138
for child in data:
@@ -142,10 +142,10 @@ def check_items_sorted(data: dict):
142142
f'after {prev_name}')
143143
prev_name = child['name']
144144
elif child['type'] == 'section':
145-
check_items_sorted(child['children'])
145+
ensure_items_sorted(child['children'])
146146

147147

148-
def main():
148+
def main() -> int:
149149
data = []
150150
errors = []
151151

@@ -182,7 +182,7 @@ def main():
182182
except Exception as e:
183183
errors.append(e)
184184

185-
check_items_sorted(data)
185+
ensure_items_sorted(data)
186186

187187
############################################################################
188188

examples/py-croniter/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from croniter import croniter
88

99

10-
def main():
10+
def main() -> int:
1111
iter = croniter('*/2 * * * *', ret_type=dt) # every 2 minutes
1212

1313
while True:

examples/pyscript-import/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env python3
22

3-
def sum_plus_three(a: int, b: int):
3+
def sum_plus_three(a: int, b: int) -> int:
44
return a + b + 3

python-scripts/binance-stats/coins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from lib.record import load_records
77

88

9-
def main(argv=None):
9+
def main(argv: list[str] = None) -> int:
1010
if argv is None:
1111
argv = sys.argv
1212

python-scripts/binance-stats/combos.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from lib.record import load_records
77

88

9-
def main(argv=None):
9+
def main(argv: list[str] = None) -> int:
1010
if argv is None:
1111
argv = sys.argv
1212

python-scripts/binance-stats/lib/ohlcv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class OHLCV:
8383
Volume) candlestick data for a trading pair
8484
'''
8585

86-
def __init__(self, base: str, quote: str, candles: list[dict]):
86+
def __init__(self, base: str, quote: str, candles: list[dict]) -> None:
8787
if len(candles) < 2:
8888
raise ValueError('Not enough candles. Minimum required: 2')
8989

@@ -205,7 +205,7 @@ class OHLCVDir:
205205
'''
206206

207207
def __init__(self, dir: str, year_first: int, year_last: int,
208-
numtype: type[float | Decimal] = float):
208+
numtype: type[float | Decimal] = float) -> None:
209209
if numtype not in (float, Decimal):
210210
raise ValueError(f'Invalid number type: {numtype}')
211211
self._numtype = numtype

python-scripts/binance-stats/lib/portfolio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Portfolio:
1414

1515
def __init__(self, balances: dict[str, float | Decimal] = {},
1616
numtype: type[float | Decimal] = Decimal,
17-
allow_negative: bool = False):
17+
allow_negative: bool = False) -> None:
1818
if numtype not in (float, Decimal):
1919
raise ValueError(f'Invalid number type: {numtype}')
2020
self._numtype = numtype

python-scripts/binance-stats/lib/record.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import csv
44

5+
from collections.abc import Iterator
56
from datetime import datetime as dt
67
from datetime import timezone as tz
78
from decimal import Decimal
8-
from typing import TextIO
9+
from typing import Any, TextIO
910

1011

1112
def load_records(file: TextIO) -> list[dict]:
@@ -54,7 +55,7 @@ def load_records(file: TextIO) -> list[dict]:
5455
return records
5556

5657

57-
def records_before(records: list[dict], dt_end: dt):
58+
def records_before(records: list[dict], dt_end: dt) -> Iterator[dict[str, Any]]:
5859
'''
5960
Returns only the records before a specific datetime.
6061
Warning: it assumes that the records are already sorted in ascending order!

python-scripts/binance-stats/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def compute_fiats(pin: Portfolio, d: dt, fiat: str,
5353
return pout
5454

5555

56-
def main(argv=None):
56+
def main(argv: list[str] = None) -> int:
5757
if argv is None:
5858
argv = sys.argv
5959

python-scripts/binance-stats/test/test_ohlcv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from lib.ohlcv import Interval, OHLCV
1414

1515

16-
def test_interval():
16+
def test_interval() -> None:
1717
cases = [
1818
(Interval.SEC01, '1s', timedelta(seconds=1)),
1919
(Interval.MIN01, '1m', timedelta(minutes=1)),
@@ -38,7 +38,7 @@ def test_interval():
3838
assert td == interval.timedelta()
3939

4040

41-
def test_ohlcv():
41+
def test_ohlcv() -> None:
4242
with pytest.raises(ValueError) as exc_info:
4343
OHLCV('BASE', 'QUOTE', [
4444
{

0 commit comments

Comments
 (0)