Skip to content

Commit 0d99098

Browse files
committed
MOD: Fix mypy warnings
1 parent 7e1799d commit 0d99098

File tree

11 files changed

+90
-148
lines changed

11 files changed

+90
-148
lines changed

databento/common/bento.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class Bento:
1717
"""The abstract base class for all Bento I/O classes."""
1818

19-
def __init__(self):
19+
def __init__(self) -> None:
2020
self._metadata: Dict[str, Any] = {}
2121
self._dtype: Optional[np.dtype] = None
2222
self._product_id_index: Dict[dt.date, Dict[int, str]] = {}

databento/historical/api/batch.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,22 @@ def submit_job(
113113
validate_enum(stype_in, SType, "stype_in")
114114
validate_enum(stype_out, SType, "stype_out")
115115

116-
schema = Schema(schema)
117-
encoding = Encoding(encoding)
118-
compression = Compression(compression)
119-
split_duration = Duration(split_duration)
120-
packaging = Packaging(packaging)
121-
delivery = Delivery(delivery)
122-
stype_in = SType(stype_in)
123-
stype_out = SType(stype_out)
124-
125116
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
126117
dataset=dataset,
127118
symbols=symbols,
128-
schema=schema,
119+
schema=Schema(schema),
129120
start=start,
130121
end=end,
131122
limit=limit,
132-
stype_in=stype_in,
133-
stype_out=stype_out,
123+
stype_in=SType(stype_in),
124+
stype_out=SType(stype_out),
134125
)
135126

136-
params.append(("encoding", encoding.value))
137-
params.append(("compression", compression.value))
138-
params.append(("split_duration", split_duration.value))
139-
params.append(("packaging", packaging.value))
140-
params.append(("delivery", delivery.value))
127+
params.append(("encoding", Encoding(encoding).value))
128+
params.append(("compression", Compression(compression).value))
129+
params.append(("split_duration", Duration(split_duration).value))
130+
params.append(("packaging", Packaging(packaging).value))
131+
params.append(("delivery", Delivery(delivery).value))
141132
if split_size is not None:
142133
params.append(("split_size", str(split_size)))
143134

@@ -172,12 +163,9 @@ def list_jobs(
172163
The batch job details.
173164
174165
"""
175-
states = maybe_values_list_to_string(states)
176-
since = maybe_datetime_to_string(since)
177-
178166
params: List[Tuple[str, str]] = [
179-
("states", states),
180-
("since", since),
167+
("states", maybe_values_list_to_string(states)),
168+
("since", maybe_datetime_to_string(since)),
181169
]
182170

183171
return self._get(

databento/historical/api/metadata.py

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ def list_datasets(
6969
List[str]
7070
7171
"""
72-
start_date = maybe_date_to_string(start_date)
73-
end_date = maybe_date_to_string(end_date)
74-
75-
params: List[Tuple[str, str]] = [
76-
("start_date", start_date),
77-
("end_date", end_date),
72+
params: List[Tuple[str, Optional[str]]] = [
73+
("start_date", maybe_date_to_string(start_date)),
74+
("end_date", maybe_date_to_string(end_date)),
7875
]
7976

8077
response: Response = self._get(
@@ -109,14 +106,10 @@ def list_schemas(
109106
List[str]
110107
111108
"""
112-
dataset = enum_or_str_lowercase(dataset, "dataset")
113-
start_date = maybe_date_to_string(start_date)
114-
end_date = maybe_date_to_string(end_date)
115-
116-
params: List[Tuple[str, str]] = [
117-
("dataset", dataset),
118-
("start_date", start_date),
119-
("end_date", end_date),
109+
params: List[Tuple[str, Optional[str]]] = [
110+
("dataset", enum_or_str_lowercase(dataset, "dataset")),
111+
("start_date", maybe_date_to_string(start_date)),
112+
("end_date", maybe_date_to_string(end_date)),
120113
]
121114

122115
response: Response = self._get(
@@ -158,14 +151,10 @@ def list_fields(
158151
validate_maybe_enum(schema, Schema, "schema")
159152
validate_maybe_enum(encoding, Encoding, "encoding")
160153

161-
dataset = enum_or_str_lowercase(dataset, "dataset")
162-
schema = maybe_enum_or_str_lowercase(schema, "schema")
163-
encoding = maybe_enum_or_str_lowercase(encoding, "encoding")
164-
165154
params: List[Tuple[str, str]] = [
166-
("dataset", dataset),
167-
("schema", schema),
168-
("encoding", encoding),
155+
("dataset", enum_or_str_lowercase(dataset, "dataset")),
156+
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
157+
("encoding", maybe_enum_or_str_lowercase(encoding, "encoding")),
169158
]
170159

171160
response: Response = self._get(
@@ -239,14 +228,10 @@ def list_unit_prices(
239228
validate_maybe_enum(schema, Schema, "schema")
240229
validate_maybe_enum(mode, FeedMode, "mode")
241230

242-
dataset = enum_or_str_lowercase(dataset, "dataset")
243-
mode = maybe_enum_or_str_lowercase(mode, "mode")
244-
schema = maybe_enum_or_str_lowercase(schema, "schema")
245-
246231
params: List[Tuple[str, str]] = [
247-
("dataset", dataset),
248-
("mode", mode),
249-
("schema", schema),
232+
("dataset", enum_or_str_lowercase(dataset, "dataset")),
233+
("mode", maybe_enum_or_str_lowercase(mode, "mode")),
234+
("schema", maybe_enum_or_str_lowercase(schema, "schema")),
250235
]
251236

252237
response: Response = self._get(
@@ -304,22 +289,14 @@ def get_shape(
304289
validate_enum(schema, Schema, "schema")
305290
validate_enum(stype_in, SType, "stype_in")
306291

307-
dataset = enum_or_str_lowercase(dataset, "dataset")
308-
symbols = maybe_symbols_list_to_string(symbols)
309-
schema = Schema(schema)
310-
start = maybe_datetime_to_string(start)
311-
end = maybe_datetime_to_string(end)
312-
encoding = Encoding(encoding)
313-
stype_in = SType(stype_in)
314-
315292
params: List[Tuple[str, str]] = [
316-
("dataset", dataset),
317-
("symbols", symbols),
318-
("schema", schema.value),
319-
("start", start),
320-
("end", end),
321-
("encoding", encoding.value),
322-
("stype_in", stype_in.value),
293+
("dataset", enum_or_str_lowercase(dataset, "dataset")),
294+
("symbols", maybe_symbols_list_to_string(symbols)),
295+
("schema", Schema(schema).value),
296+
("start", maybe_datetime_to_string(start)),
297+
("end", maybe_datetime_to_string(end)),
298+
("encoding", Encoding(encoding).value),
299+
("stype_in", SType(stype_in).value),
323300
]
324301
if limit is not None:
325302
params.append(("limit", str(limit)))
@@ -378,16 +355,13 @@ def get_billable_size(
378355
validate_enum(schema, Schema, "schema")
379356
validate_enum(stype_in, SType, "stype_in")
380357

381-
schema = Schema(schema)
382-
stype_in = SType(stype_in)
383-
384358
params: List[Tuple[str, str]] = super()._timeseries_params(
385359
dataset=dataset,
386360
symbols=symbols,
387-
schema=schema,
361+
schema=Schema(schema),
388362
start=start,
389363
end=end,
390-
stype_in=stype_in,
364+
stype_in=SType(stype_in),
391365
limit=limit,
392366
)
393367

@@ -448,21 +422,17 @@ def get_cost(
448422
validate_enum(schema, Schema, "schema")
449423
validate_enum(stype_in, SType, "stype_in")
450424

451-
mode = FeedMode(mode)
452-
schema = Schema(schema)
453-
stype_in = SType(stype_in)
454-
455425
params: List[Tuple[str, str]] = super()._timeseries_params(
456426
dataset=dataset,
457427
symbols=symbols,
458-
schema=schema,
428+
schema=Schema(schema),
459429
start=start,
460430
end=end,
461-
stype_in=stype_in,
431+
stype_in=SType(stype_in),
462432
limit=limit,
463433
)
464434

465-
params.append(("mode", mode.value))
435+
params.append(("mode", FeedMode(mode).value))
466436

467437
response: Response = self._get(
468438
url=self._base_url + ".get_cost",

databento/historical/api/symbology.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,13 @@ def resolve(
5757
date range.
5858
5959
"""
60-
dataset = enum_or_str_lowercase(dataset, "dataset")
61-
symbols = maybe_symbols_list_to_string(symbols)
62-
stype_in = enum_or_str_lowercase(stype_in, "stype_in")
63-
stype_out = enum_or_str_lowercase(stype_out, "stype_out")
64-
start_date = str(pd.to_datetime(start_date).date())
65-
end_date = str(pd.to_datetime(end_date).date())
66-
67-
params: List[Tuple[str, str]] = [
68-
("dataset", dataset),
69-
("symbols", symbols),
70-
("stype_in", stype_in),
71-
("stype_out", stype_out),
72-
("start_date", start_date),
73-
("end_date", end_date),
60+
params: List[Tuple[str, Optional[str]]] = [
61+
("dataset", enum_or_str_lowercase(dataset, "dataset")),
62+
("symbols", maybe_symbols_list_to_string(symbols)),
63+
("stype_in", enum_or_str_lowercase(stype_in, "stype_in")),
64+
("stype_out", enum_or_str_lowercase(stype_out, "stype_out")),
65+
("start_date", str(pd.to_datetime(start_date).date())),
66+
("end_date", str(pd.to_datetime(end_date).date())),
7467
("default_value", default_value),
7568
]
7669

databento/historical/api/timeseries.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,22 @@ def stream(
7979
validate_enum(stype_in, SType, "stype_in")
8080
validate_enum(stype_out, SType, "stype_out")
8181

82-
schema = Schema(schema)
83-
stype_in = SType(stype_in)
84-
stype_out = SType(stype_out)
85-
8682
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
8783
dataset=dataset,
8884
symbols=symbols,
89-
schema=schema,
85+
schema=Schema(schema),
9086
start=start,
9187
end=end,
92-
stype_in=stype_in,
93-
stype_out=stype_out,
88+
stype_in=SType(stype_in),
89+
stype_out=SType(stype_out),
9490
limit=limit,
9591
)
9692

9793
params.append(("encoding", Encoding.DBZ.value)) # Always requests DBZ
9894

9995
self._pre_check_data_size(
10096
symbols=symbols,
101-
schema=schema,
97+
schema=Schema(schema),
10298
start=start,
10399
end=end,
104100
limit=limit,
@@ -175,26 +171,22 @@ async def stream_async(
175171
validate_enum(stype_in, SType, "stype_in")
176172
validate_enum(stype_out, SType, "stype_out")
177173

178-
schema = Schema(schema)
179-
stype_in = SType(stype_in)
180-
stype_out = SType(stype_out)
181-
182174
params: List[Tuple[str, str]] = BentoHttpAPI._timeseries_params(
183175
dataset=dataset,
184176
symbols=symbols,
185-
schema=schema,
177+
schema=Schema(schema),
186178
start=start,
187179
end=end,
188-
stype_in=stype_in,
189-
stype_out=stype_out,
180+
stype_in=SType(stype_in),
181+
stype_out=SType(stype_out),
190182
limit=limit,
191183
)
192184

193185
params.append(("encoding", Encoding.DBZ.value)) # Always requests DBZ
194186

195187
self._pre_check_data_size(
196188
symbols=symbols,
197-
schema=schema,
189+
schema=Schema(schema),
198190
start=start,
199191
end=end,
200192
limit=limit,
@@ -211,14 +203,14 @@ async def stream_async(
211203

212204
return bento
213205

214-
def _pre_check_data_size(
206+
def _pre_check_data_size( # noqa (prefer not to make static)
215207
self,
216208
symbols: Optional[Union[List[str], str]],
217209
schema: Schema,
218210
start: Optional[Union[pd.Timestamp, date, str, int]],
219211
end: Optional[Union[pd.Timestamp, date, str, int]],
220212
limit: Optional[int],
221-
):
213+
) -> None:
222214
if limit and limit < 10**7:
223215
return
224216

@@ -240,7 +232,7 @@ def _pre_check_data_size(
240232
)
241233

242234

243-
def _is_large_number_of_symbols(symbols: Optional[Union[List[str], str]]):
235+
def _is_large_number_of_symbols(symbols: Optional[Union[List[str], str]]) -> bool:
244236
if not symbols:
245237
return True # All symbols
246238

@@ -253,11 +245,11 @@ def _is_large_number_of_symbols(symbols: Optional[Union[List[str], str]]):
253245
return False
254246

255247

256-
def _is_large_data_size_schema(schema: Schema):
248+
def _is_large_data_size_schema(schema: Schema) -> bool:
257249
return schema in (Schema.MBO, Schema.MBP_10)
258250

259251

260-
def _is_greater_than_one_day(start, end):
252+
def _is_greater_than_one_day(start, end) -> bool:
261253
if start is None or end is None:
262254
return True
263255

databento/historical/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from datetime import date
33
from json.decoder import JSONDecodeError
4-
from typing import Any, BinaryIO, List, Optional, Tuple, Union
4+
from typing import Any, BinaryIO, List, Optional, Sequence, Tuple, Union
55

66
import aiohttp
77
import pandas as pd
@@ -78,7 +78,7 @@ def _create_bento(path: str) -> Union[MemoryBento, FileBento]:
7878
else:
7979
return FileBento(path=path)
8080

81-
def _check_api_key(self):
81+
def _check_api_key(self) -> None:
8282
if self._key == "YOUR_API_KEY":
8383
raise ValueError(
8484
"The API key is currently set to 'YOUR_API_KEY'. "
@@ -185,7 +185,7 @@ def _stream(
185185
async def _stream_async(
186186
self,
187187
url: str,
188-
params: List[Tuple[str, Optional[str]]],
188+
params: Sequence[Tuple[str, Optional[str]]],
189189
basic_auth: bool,
190190
bento: Bento,
191191
) -> None:

examples/historical_timeseries_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from databento import Bento
66

77

8-
async def request_stream_async():
8+
async def request_stream_async() -> None:
99
db.log = "debug" # optional debug logging
1010

1111
key = "YOUR_API_KEY"

tests/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
TESTS_ROOT = os.path.dirname(os.path.abspath(__file__))
77

88

9-
def get_test_data_path(schema: Schema):
9+
def get_test_data_path(schema: Schema) -> str:
1010
return os.path.join(TESTS_ROOT, "data", f"test_data.{schema.value}.dbz")
1111

1212

13-
def get_test_data(schema: Schema):
13+
def get_test_data(schema: Schema) -> bytes:
1414
with open(get_test_data_path(schema=schema), "rb") as f:
1515
return f.read()

0 commit comments

Comments
 (0)