Skip to content

Commit ab5d54d

Browse files
committed
REF: Remove Number in type hints for Python client
1 parent d1dd6d5 commit ab5d54d

File tree

9 files changed

+39
-48
lines changed

9 files changed

+39
-48
lines changed

databento/common/parsing.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from datetime import date
55
from functools import partial
66
from functools import singledispatch
7-
from numbers import Number
7+
from numbers import Integral
8+
from typing import Any
89

910
import pandas as pd
1011
from databento_dbn import SType
@@ -59,7 +60,7 @@ def optional_values_list_to_string(
5960

6061
@singledispatch
6162
def optional_symbols_list_to_list(
62-
symbols: Iterable[str] | Iterable[Number] | str | Number | None,
63+
symbols: Iterable[str | int | Integral] | str | int | Integral | None,
6364
stype_in: SType,
6465
) -> list[str]:
6566
"""
@@ -68,7 +69,7 @@ def optional_symbols_list_to_list(
6869
6970
Parameters
7071
----------
71-
symbols : iterable of str, iterable of Number, str, or Number optional
72+
symbols : Iterable of str or int or Number, or str or int or Number, optional
7273
The symbols to concatenate.
7374
stype_in : SType
7475
The input symbology type for the request.
@@ -84,7 +85,7 @@ def optional_symbols_list_to_list(
8485
"""
8586
raise TypeError(
8687
f"`{symbols}` is not a valid type for symbol input; "
87-
"allowed types are Iterable[str], Iterable[int], str, int, and None.",
88+
"allowed types are Iterable[str | int], str, int, and None.",
8889
)
8990

9091

@@ -102,10 +103,10 @@ def _(_: None, __: SType) -> list[str]:
102103
return [ALL_SYMBOLS]
103104

104105

105-
@optional_symbols_list_to_list.register(cls=Number)
106-
def _(symbols: Number, stype_in: SType) -> list[str]:
106+
@optional_symbols_list_to_list.register(cls=Integral)
107+
def _(symbols: Integral, stype_in: SType) -> list[str]:
107108
"""
108-
Dispatch method for optional_symbols_list_to_list. Handles numerical types,
109+
Dispatch method for optional_symbols_list_to_list. Handles integral types,
109110
alerting when an integer is given for STypes that expect strings.
110111
111112
See Also
@@ -147,7 +148,7 @@ def _(symbols: str, stype_in: SType) -> list[str]:
147148

148149

149150
@optional_symbols_list_to_list.register(cls=Iterable)
150-
def _(symbols: Iterable[str] | Iterable[int], stype_in: SType) -> list[str]:
151+
def _(symbols: Iterable[Any], stype_in: SType) -> list[str]:
151152
"""
152153
Dispatch method for optional_symbols_list_to_list. Handles Iterables by
153154
dispatching the individual members.

databento/historical/api/batch.py

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

33
import logging
44
import os
5+
from collections.abc import Iterable
56
from datetime import date
67
from os import PathLike
78
from pathlib import Path
@@ -48,7 +49,7 @@ def __init__(self, key: str, gateway: str) -> None:
4849
def submit_job(
4950
self,
5051
dataset: Dataset | str,
51-
symbols: list[str] | str,
52+
symbols: Iterable[str | int] | str | int,
5253
schema: Schema | str,
5354
start: pd.Timestamp | date | str | int,
5455
end: pd.Timestamp | date | str | int | None = None,
@@ -75,7 +76,7 @@ def submit_job(
7576
----------
7677
dataset : Dataset or str
7778
The dataset code (string identifier) for the request.
78-
symbols : list[str | int] or str
79+
symbols : Iterable[str | int] or str or int
7980
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
8081
If more than 1 symbol is specified, the data is merged and sorted by time.
8182
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.

databento/historical/api/metadata.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterable
34
from datetime import date
45
from typing import Any
56

@@ -261,7 +262,7 @@ def get_record_count(
261262
dataset: Dataset | str,
262263
start: pd.Timestamp | date | str | int,
263264
end: pd.Timestamp | date | str | int | None = None,
264-
symbols: list[str] | str | None = None,
265+
symbols: Iterable[str | int] | str | int | None = None,
265266
schema: Schema | str = "trades",
266267
stype_in: SType | str = "raw_symbol",
267268
limit: int | None = None,
@@ -285,7 +286,7 @@ def get_record_count(
285286
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
286287
Values are forward filled based on the resolution provided.
287288
Defaults to the same value as `start`.
288-
symbols : list[str | int] or str, optional
289+
symbols : Iterable[str | int] or str or int, optional
289290
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
290291
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
291292
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa
@@ -329,7 +330,7 @@ def get_billable_size(
329330
dataset: Dataset | str,
330331
start: pd.Timestamp | date | str | int,
331332
end: pd.Timestamp | date | str | int | None = None,
332-
symbols: list[str] | str | None = None,
333+
symbols: Iterable[str | int] | str | int | None = None,
333334
schema: Schema | str = "trades",
334335
stype_in: SType | str = "raw_symbol",
335336
limit: int | None = None,
@@ -354,7 +355,7 @@ def get_billable_size(
354355
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
355356
Values are forward filled based on the resolution provided.
356357
Defaults to the same value as `start`.
357-
symbols : list[str | int] or str, optional
358+
symbols : Iterable[str | int] or str or int, optional
358359
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
359360
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
360361
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa
@@ -399,7 +400,7 @@ def get_cost(
399400
start: pd.Timestamp | date | str | int,
400401
end: pd.Timestamp | date | str | int | None = None,
401402
mode: FeedMode | str = "historical-streaming",
402-
symbols: list[str] | str | None = None,
403+
symbols: Iterable[str | int] | str | int | None = None,
403404
schema: Schema | str = "trades",
404405
stype_in: SType | str = "raw_symbol",
405406
limit: int | None = None,
@@ -426,7 +427,7 @@ def get_cost(
426427
Defaults to the same value as `start`.
427428
mode : FeedMode or str {'live', 'historical-streaming', 'historical'}, default 'historical-streaming'
428429
The data feed mode for the request.
429-
symbols : list[str | int] or str, optional
430+
symbols : Iterable[str | int] or str or int, optional
430431
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
431432
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
432433
schema : Schema or str {'mbo', 'mbp-1', 'mbp-10', 'trades', 'tbbo', 'ohlcv-1s', 'ohlcv-1m', 'ohlcv-1h', 'ohlcv-1d', 'definition', 'statistics', 'status'}, default 'trades' # noqa

databento/historical/api/symbology.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterable
34
from datetime import date
45
from typing import Any
56

@@ -28,7 +29,7 @@ def __init__(self, key: str, gateway: str) -> None:
2829
def resolve(
2930
self,
3031
dataset: Dataset | str,
31-
symbols: list[str] | str,
32+
symbols: Iterable[str | int] | str | int,
3233
stype_in: SType | str,
3334
stype_out: SType | str,
3435
start_date: date | str,
@@ -43,7 +44,7 @@ def resolve(
4344
----------
4445
dataset : Dataset or str
4546
The dataset code (string identifier) for the request.
46-
symbols : list[str | int] or str, optional
47+
symbols : Iterable[str | int] or str or int, optional
4748
The symbols to resolve. Takes up to 2,000 symbols per request.
4849
stype_in : SType or str, default 'raw_symbol'
4950
The input symbology type to resolve from.

databento/historical/api/timeseries.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from collections.abc import Iterable
34
from datetime import date
45
from os import PathLike
56

@@ -35,7 +36,7 @@ def get_range(
3536
dataset: Dataset | str,
3637
start: pd.Timestamp | date | str | int,
3738
end: pd.Timestamp | date | str | int | None = None,
38-
symbols: list[str] | str | None = None,
39+
symbols: Iterable[str | int] | str | int | None = None,
3940
schema: Schema | str = "trades",
4041
stype_in: SType | str = "raw_symbol",
4142
stype_out: SType | str = "instrument_id",
@@ -67,7 +68,7 @@ def get_range(
6768
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
6869
Values are forward filled based on the resolution provided.
6970
Defaults to the same value as `start`.
70-
symbols : list[str | instr | intt] or str, optional
71+
symbols : Iterable[str | int], or str, or int, optional
7172
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
7273
If more than 1 symbol is specified, the data is merged and sorted by time.
7374
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.
@@ -131,7 +132,7 @@ async def get_range_async(
131132
dataset: Dataset | str,
132133
start: pd.Timestamp | date | str | int,
133134
end: pd.Timestamp | date | str | int | None = None,
134-
symbols: list[str] | str | None = None,
135+
symbols: Iterable[str | int] | str | int | None = None,
135136
schema: Schema | str = "trades",
136137
stype_in: SType | str = "raw_symbol",
137138
stype_out: SType | str = "instrument_id",
@@ -164,7 +165,7 @@ async def get_range_async(
164165
If an integer is passed, then this represents nanoseconds since the UNIX epoch.
165166
Values are forward filled based on the resolution provided.
166167
Defaults to the same value as `start`.
167-
symbols : list[str | int] or str, optional
168+
symbols : Iterable[str | int] or str or int, optional
168169
The instrument symbols to filter for. Takes up to 2,000 symbols per request.
169170
If more than 1 symbol is specified, the data is merged and sorted by time.
170171
If 'ALL_SYMBOLS' or `None` then will be for **all** symbols.

databento/live/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import threading
99
from collections.abc import Iterable
1010
from concurrent import futures
11-
from numbers import Number
1211
from os import PathLike
1312
from typing import IO, Final
1413

@@ -409,7 +408,7 @@ def subscribe(
409408
self,
410409
dataset: Dataset | str,
411410
schema: Schema | str,
412-
symbols: Iterable[str] | Iterable[Number] | str | Number = ALL_SYMBOLS,
411+
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
413412
stype_in: SType | str = SType.RAW_SYMBOL,
414413
start: str | int | None = None,
415414
) -> None:
@@ -428,7 +427,7 @@ def subscribe(
428427
The dataset for the subscription.
429428
schema : Schema or str
430429
The schema to subscribe to.
431-
symbols : Iterable[str | Number] or str or Number, default 'ALL_SYMBOLS'
430+
symbols : Iterable[str | int] or str or int, default 'ALL_SYMBOLS'
432431
The symbols to subscribe to.
433432
stype_in : SType or str, default 'raw_symbol'
434433
The input symbology type to resolve from.

databento/live/protocol.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
from collections.abc import Iterable
66
from functools import singledispatchmethod
7-
from numbers import Number
87
from typing import Final
98

109
import databento_dbn
@@ -52,7 +51,7 @@ class DatabentoLiveProtocol(asyncio.BufferedProtocol):
5251
----------
5352
api_key : str
5453
The user API key for authentication.
55-
dataset : Dataset, or str
54+
dataset : Dataset or str
5655
The dataset for authentication.
5756
ts_out : bool, default False
5857
Flag for requesting `ts_out` to be appending to all records in the session.
@@ -253,7 +252,7 @@ def received_record(self, record: DBNRecord) -> None:
253252
def subscribe(
254253
self,
255254
schema: Schema | str,
256-
symbols: Iterable[str] | Iterable[Number] | str | Number = ALL_SYMBOLS,
255+
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
257256
stype_in: SType | str = SType.RAW_SYMBOL,
258257
start: str | int | None = None,
259258
) -> None:
@@ -264,7 +263,7 @@ def subscribe(
264263
----------
265264
schema : Schema or str
266265
The schema to subscribe to.
267-
symbols : Iterable[str | Number] or str or Number, default 'ALL_SYMBOLS'
266+
symbols : Iterable[str | int] or str or int, default 'ALL_SYMBOLS'
268267
The symbols to subscribe to.
269268
stype_in : SType or str, default 'raw_symbol'
270269
The input symbology type to resolve from.

databento/live/session.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import queue
77
import threading
88
from collections.abc import Iterable
9-
from numbers import Number
109
from typing import IO, Callable, Final
1110

1211
import databento_dbn
@@ -335,7 +334,7 @@ def subscribe(
335334
self,
336335
dataset: Dataset | str,
337336
schema: Schema | str,
338-
symbols: Iterable[str] | Iterable[Number] | str | Number = ALL_SYMBOLS,
337+
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
339338
stype_in: SType | str = SType.RAW_SYMBOL,
340339
start: str | int | None = None,
341340
) -> None:
@@ -345,11 +344,11 @@ def subscribe(
345344
346345
Parameters
347346
----------
348-
dataset : Dataset, str
347+
dataset : Dataset or str
349348
The dataset for the subscription.
350349
schema : Schema or str
351350
The schema to subscribe to.
352-
symbols : Iterable[str | Number] or str or Number, default 'ALL_SYMBOLS'
351+
symbols : Iterable[str | int] or str or int, default 'ALL_SYMBOLS'
353352
The symbols to subscribe to.
354353
stype_in : SType or str, default 'raw_symbol'
355354
The input symbology type to resolve from.
@@ -503,7 +502,7 @@ async def _connect_task(
503502
async def _subscribe_task(
504503
self,
505504
schema: Schema | str,
506-
symbols: Iterable[str] | Iterable[Number] | str | Number = ALL_SYMBOLS,
505+
symbols: Iterable[str | int] | str | int = ALL_SYMBOLS,
507506
stype_in: SType | str = SType.RAW_SYMBOL,
508507
start: str | int | None = None,
509508
) -> None:

tests/test_common_parsing.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import datetime as dt
4-
from numbers import Number
54
from typing import Any
65

76
import numpy as np
@@ -105,7 +104,7 @@ def test_optional_symbols_list_to_list_given_valid_inputs_returns_expected(
105104
],
106105
)
107106
def test_optional_symbols_list_to_list_int(
108-
symbols: list[Number] | Number | None,
107+
symbols: list[int] | int | None,
109108
stype: SType,
110109
expected: list[object] | type[Exception],
111110
) -> None:
@@ -138,20 +137,10 @@ def test_optional_symbols_list_to_list_int(
138137
SType.INSTRUMENT_ID,
139138
["12345", "67890"],
140139
),
141-
pytest.param(
142-
[np.int_(12345), np.longlong(67890)],
143-
SType.INSTRUMENT_ID,
144-
["12345", "67890"],
145-
),
146-
pytest.param(
147-
[np.int_(12345), np.longlong(67890)],
148-
SType.INSTRUMENT_ID,
149-
["12345", "67890"],
150-
),
151140
],
152141
)
153142
def test_optional_symbols_list_to_list_numpy(
154-
symbols: list[Number] | Number | None,
143+
symbols: list[int] | int | None,
155144
stype: SType,
156145
expected: list[object] | type[Exception],
157146
) -> None:
@@ -190,7 +179,7 @@ def test_optional_symbols_list_to_list_numpy(
190179
],
191180
)
192181
def test_optional_symbols_list_to_list_raw_symbol(
193-
symbols: list[Number] | Number | None,
182+
symbols: list[int] | int | None,
194183
stype: SType,
195184
expected: list[object] | type[Exception],
196185
) -> None:

0 commit comments

Comments
 (0)