Skip to content

Commit 940d9ad

Browse files
author
Zach Banks
committed
BLD: Add disallow_incomplete_defs flag to mypy
1 parent 0d99098 commit 940d9ad

File tree

9 files changed

+80
-41
lines changed

9 files changed

+80
-41
lines changed

databento/common/bento.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime as dt
22
import io
33
import os.path
4-
from typing import Any, BinaryIO, Callable, Dict, List, Optional, Tuple
4+
from typing import TYPE_CHECKING, Any, BinaryIO, Callable, Dict, List, Optional, Tuple
55

66
import numpy as np
77
import pandas as pd
@@ -13,6 +13,10 @@
1313
from databento.common.symbology import ProductIdMappingInterval
1414

1515

16+
if TYPE_CHECKING:
17+
from databento.historical.client import Historical
18+
19+
1620
class Bento:
1721
"""The abstract base class for all Bento I/O classes."""
1822

@@ -590,7 +594,7 @@ def to_json(self, path: str) -> None:
590594
"""
591595
self.to_df().to_json(path, orient="records", lines=True)
592596

593-
def request_symbology(self, client) -> Dict[str, Any]:
597+
def request_symbology(self, client: "Historical") -> Dict[str, Any]:
594598
"""
595599
Request symbology resolution based on the metadata properties.
596600
@@ -622,7 +626,7 @@ def request_symbology(self, client) -> Dict[str, Any]:
622626

623627
def request_full_definitions(
624628
self,
625-
client,
629+
client: "Historical",
626630
path: Optional[str] = None,
627631
) -> "Bento":
628632
"""

databento/common/logging.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import sys
4+
from typing import Optional
45

56
import databento
67

@@ -14,7 +15,7 @@
1415
_ERROR = "ERROR"
1516

1617

17-
def _console_log_level():
18+
def _console_log_level() -> Optional[str]:
1819
if databento.log:
1920
databento.log = databento.log.upper()
2021

@@ -26,23 +27,23 @@ def _console_log_level():
2627
return None
2728

2829

29-
def log_debug(msg: str):
30+
def log_debug(msg: str) -> None:
3031
"""Log the given message with DEBUG level."""
3132
log_level = _console_log_level()
3233
if log_level == [_DEBUG, _INFO, _ERROR]:
3334
print(f"DEBUG: {msg}", file=sys.stderr)
3435
logger.debug(msg)
3536

3637

37-
def log_info(msg: str):
38+
def log_info(msg: str) -> None:
3839
"""Log the given message with INFO level."""
3940
log_level = _console_log_level()
4041
if log_level in [_INFO, _ERROR]:
4142
print(f"INFO: {msg}", file=sys.stderr)
4243
logger.info(msg)
4344

4445

45-
def log_error(msg: str):
46+
def log_error(msg: str) -> None:
4647
"""Log the given message with ERROR level."""
4748
log_level = _console_log_level()
4849
if log_level in [_ERROR]:

databento/historical/api/timeseries.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ def _is_large_data_size_schema(schema: Schema) -> bool:
249249
return schema in (Schema.MBO, Schema.MBP_10)
250250

251251

252-
def _is_greater_than_one_day(start, end) -> bool:
252+
def _is_greater_than_one_day(
253+
start: Optional[Union[pd.Timestamp, date, str, int]],
254+
end: Optional[Union[pd.Timestamp, date, str, int]],
255+
) -> bool:
253256
if start is None or end is None:
254257
return True
255258

tests/test_common_validation.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from enum import Enum
2+
from typing import Any, Type, Union
3+
14
import pytest
25
from databento.common.enums import Compression, Encoding
36
from databento.common.validation import validate_enum, validate_maybe_enum
@@ -13,9 +16,9 @@ class TestValidation:
1316
)
1417
def test_validate_enum_given_wrong_types_raises_type_error(
1518
self,
16-
value,
17-
enum,
18-
param,
19+
value: Any,
20+
enum: Type[Enum],
21+
param: str,
1922
) -> None:
2023
# Arrange, Act, Assert
2124
with pytest.raises(TypeError):
@@ -36,10 +39,10 @@ def test_validate_enum_given_invalid_value_raises_value_error(self) -> None:
3639
)
3740
def test_validate_enum_given_valid_value_returns_expected_output(
3841
self,
39-
value,
40-
enum,
41-
param,
42-
expected,
42+
value: Union[str, Enum],
43+
enum: Type[Enum],
44+
param: str,
45+
expected: Union[str, Enum],
4346
) -> None:
4447
# Arrange, Act, Assert
4548
assert validate_enum(value, enum, "param") == expected

tests/test_historical_batch.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import databento as db
44
import pytest
55
import requests
6+
from pytest_mock import MockerFixture
67

78

89
class TestHistoricalBatch:
@@ -49,7 +50,9 @@ def test_batch_submit_job_given_invalid_stype_in_raises_error(self) -> None:
4950
)
5051

5152
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
52-
def test_batch_submit_job_sends_expected_request(self, mocker) -> None:
53+
def test_batch_submit_job_sends_expected_request(
54+
self, mocker: MockerFixture
55+
) -> None:
5356
# Arrange
5457
mocked_get = mocker.patch("requests.post")
5558

@@ -98,7 +101,9 @@ def test_batch_submit_job_sends_expected_request(self, mocker) -> None:
98101
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
99102

100103
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
101-
def test_batch_list_jobs_sends_expected_request(self, mocker) -> None:
104+
def test_batch_list_jobs_sends_expected_request(
105+
self, mocker: MockerFixture
106+
) -> None:
102107
# Arrange
103108
mocked_get = mocker.patch("requests.get")
104109

tests/test_historical_bento.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44
from pathlib import Path
5-
from typing import Union
5+
from typing import List, Tuple, Union
66

77
import numpy as np
88
import pandas as pd
@@ -201,7 +201,7 @@ def test_replay_with_stub_data_record_passes_to_callback(self) -> None:
201201
stub_data = get_test_data(schema=Schema.MBO)
202202
data = MemoryBento(initial_bytes=stub_data)
203203

204-
handler: list[tuple[Union[int, bytes], ...]] = []
204+
handler: List[Tuple[Union[int, bytes], ...]] = []
205205

206206
# Act
207207
data.replay(callback=handler.append)
@@ -227,7 +227,9 @@ def test_replay_with_stub_data_record_passes_to_callback(self) -> None:
227227
)
228228
],
229229
)
230-
def test_to_df_across_schemas_returns_identical_dimension_dfs(self, schema) -> None:
230+
def test_to_df_across_schemas_returns_identical_dimension_dfs(
231+
self, schema: Schema
232+
) -> None:
231233
# Arrange
232234
stub_data = get_test_data(schema=schema)
233235
data = MemoryBento(initial_bytes=stub_data)
@@ -334,8 +336,8 @@ def test_to_df_with_pretty_ts_converts_timestamps_as_expected(self) -> None:
334336
)
335337
def test_to_df_with_pretty_px_with_various_schemas_converts_prices_as_expected(
336338
self,
337-
schema,
338-
columns,
339+
schema: Schema,
340+
columns: List[str],
339341
) -> None:
340342
# Arrange
341343
stub_data = get_test_data(schema=schema)
@@ -366,9 +368,9 @@ def test_to_df_with_pretty_px_with_various_schemas_converts_prices_as_expected(
366368
)
367369
def test_from_file_given_various_paths_returns_expected_metadata(
368370
self,
369-
expected_schema,
370-
expected_encoding,
371-
expected_compression,
371+
expected_schema: Schema,
372+
expected_encoding: Encoding,
373+
expected_compression: Compression,
372374
) -> None:
373375
# Arrange, Act
374376
path = get_test_data_path(schema=expected_schema)

tests/test_historical_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import sys
2+
from typing import Union
23

34
import databento as db
45
import pytest
56
import requests
67
from databento import FileBento, Historical
78
from databento.common.enums import HistoricalGateway, Schema
9+
from pytest_mock import MockerFixture
810
from tests.fixtures import get_test_data_path
911

1012

@@ -37,8 +39,8 @@ def test_default_host_returns_expected(self) -> None:
3739
)
3840
def test_gateway_nearest_and_bo1_map_to_hist_databento(
3941
self,
40-
gateway,
41-
expected,
42+
gateway: Union[HistoricalGateway, str],
43+
expected: str,
4244
) -> None:
4345
# Arrange, Act
4446
client = db.Historical(key="DUMMY_API_KEY", gateway=gateway)
@@ -57,7 +59,9 @@ def test_custom_gateway_returns_expected(self) -> None:
5759
assert client.gateway == ny4_gateway
5860

5961
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
60-
def test_re_request_symbology_makes_expected_request(self, mocker) -> None:
62+
def test_re_request_symbology_makes_expected_request(
63+
self, mocker: MockerFixture
64+
) -> None:
6165
# Arrange
6266
mocked_get = mocker.patch("requests.get")
6367

@@ -93,7 +97,9 @@ def test_re_request_symbology_makes_expected_request(self, mocker) -> None:
9397
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
9498

9599
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
96-
def test_request_full_definitions_expected_request(self, mocker) -> None:
100+
def test_request_full_definitions_expected_request(
101+
self, mocker: MockerFixture
102+
) -> None:
97103
# Arrange
98104
mocked_get = mocker.patch("requests.get")
99105

tests/test_historical_metadata.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import sys
2+
from typing import Union
23

34
import databento as db
45
import pytest
56
import requests
67
from databento.common.enums import Dataset, FeedMode, Schema
8+
from pytest_mock import MockerFixture
79

810

911
class TestHistoricalMetadata:
@@ -12,7 +14,9 @@ def setup(self) -> None:
1214
self.client = db.Historical(key=key)
1315

1416
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
15-
def test_list_publishers_sends_expected_request(self, mocker) -> None:
17+
def test_list_publishers_sends_expected_request(
18+
self, mocker: MockerFixture
19+
) -> None:
1620
# Arrange
1721
mocked_get = mocker.patch("requests.get")
1822

@@ -34,7 +38,7 @@ def test_list_publishers_sends_expected_request(self, mocker) -> None:
3438
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
3539

3640
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
37-
def test_list_datasets_sends_expected_request(self, mocker) -> None:
41+
def test_list_datasets_sends_expected_request(self, mocker: MockerFixture) -> None:
3842
# Arrange
3943
mocked_get = mocker.patch("requests.get")
4044

@@ -61,7 +65,7 @@ def test_list_datasets_sends_expected_request(self, mocker) -> None:
6165
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
6266

6367
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
64-
def test_list_schemas_sends_expected_request(self, mocker) -> None:
68+
def test_list_schemas_sends_expected_request(self, mocker: MockerFixture) -> None:
6569
# Arrange
6670
mocked_get = mocker.patch("requests.get")
6771

@@ -89,7 +93,7 @@ def test_list_schemas_sends_expected_request(self, mocker) -> None:
8993
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
9094

9195
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
92-
def test_list_fields_sends_expected_request(self, mocker) -> None:
96+
def test_list_fields_sends_expected_request(self, mocker: MockerFixture) -> None:
9397
# Arrange
9498
mocked_get = mocker.patch("requests.get")
9599

@@ -117,7 +121,7 @@ def test_list_fields_sends_expected_request(self, mocker) -> None:
117121
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
118122

119123
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
120-
def test_list_encodings_sends_expected_request(self, mocker) -> None:
124+
def test_list_encodings_sends_expected_request(self, mocker: MockerFixture) -> None:
121125
# Arrange
122126
mocked_get = mocker.patch("requests.get")
123127

@@ -139,7 +143,9 @@ def test_list_encodings_sends_expected_request(self, mocker) -> None:
139143
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
140144

141145
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
142-
def test_list_compressions_sends_expected_request(self, mocker) -> None:
146+
def test_list_compressions_sends_expected_request(
147+
self, mocker: MockerFixture
148+
) -> None:
143149
# Arrange
144150
mocked_get = mocker.patch("requests.get")
145151

@@ -169,7 +175,11 @@ def test_list_compressions_sends_expected_request(self, mocker) -> None:
169175
],
170176
)
171177
def test_list_unit_price_sends_expected_request(
172-
self, dataset, schema, mode, mocker
178+
self,
179+
dataset: Union[str, Dataset],
180+
schema: Union[str, Schema],
181+
mode: Union[str, FeedMode],
182+
mocker: MockerFixture,
173183
) -> None:
174184
# Arrange
175185
mocked_get = mocker.patch("requests.get")
@@ -201,7 +211,7 @@ def test_list_unit_price_sends_expected_request(
201211
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
202212

203213
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
204-
def test_get_shape_sends_expected_request(self, mocker) -> None:
214+
def test_get_shape_sends_expected_request(self, mocker: MockerFixture) -> None:
205215
# Arrange
206216
mocked_get = mocker.patch("requests.get")
207217

@@ -240,7 +250,9 @@ def test_get_shape_sends_expected_request(self, mocker) -> None:
240250
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
241251

242252
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
243-
def test_get_billable_size_sends_expected_request(self, mocker) -> None:
253+
def test_get_billable_size_sends_expected_request(
254+
self, mocker: MockerFixture
255+
) -> None:
244256
# Arrange
245257
mocked_get = mocker.patch("requests.get")
246258

@@ -279,7 +291,7 @@ def test_get_billable_size_sends_expected_request(self, mocker) -> None:
279291
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
280292

281293
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
282-
def test_get_cost_sends_expected_request(self, mocker) -> None:
294+
def test_get_cost_sends_expected_request(self, mocker: MockerFixture) -> None:
283295
# Arrange
284296
mocked_get = mocker.patch("requests.get")
285297

tests/test_historical_timeseries.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import databento as db
44
import pytest
55
import requests
6+
from pytest_mock import MockerFixture
67

78

89
class TestHistoricalTimeSeries:
@@ -46,7 +47,7 @@ def test_stream_given_invalid_stype_out_raises_error(self) -> None:
4647
)
4748

4849
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
49-
def test_stream_sends_expected_request(self, mocker) -> None:
50+
def test_stream_sends_expected_request(self, mocker: MockerFixture) -> None:
5051
# Arrange
5152
mocked_get = mocker.patch("requests.get")
5253

@@ -84,7 +85,9 @@ def test_stream_sends_expected_request(self, mocker) -> None:
8485
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
8586

8687
@pytest.mark.skipif(sys.version_info < (3, 8), reason="incompatible mocking")
87-
def test_stream_with_limit_sends_expected_request(self, mocker) -> None:
88+
def test_stream_with_limit_sends_expected_request(
89+
self, mocker: MockerFixture
90+
) -> None:
8891
# Arrange
8992
mocked_get = mocker.patch("requests.get")
9093

0 commit comments

Comments
 (0)