Skip to content

Commit 7b9b5b5

Browse files
committed
REF: Fix more mypy warnings
1 parent 26cf26d commit 7b9b5b5

File tree

7 files changed

+39
-50
lines changed

7 files changed

+39
-50
lines changed

databento/common/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any, Callable, Dict
22

33
from databento.common.parsing import int_to_compression, int_to_schema, int_to_stype
44
from dbz_python import decode_metadata
@@ -25,7 +25,7 @@ def decode_to_json(raw_metadata: bytes) -> Dict[str, Any]:
2525
2626
"""
2727

28-
def enum_value(fn):
28+
def enum_value(fn: Callable) -> Any:
2929
return lambda x: fn(x).value
3030

3131
metadata = decode_metadata(raw_metadata)

databento/common/symbology.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import datetime as dt
2+
from dataclasses import dataclass
23

34

5+
@dataclass(frozen=True)
46
class ProductIdMappingInterval:
57
"""
68
Represents a product ID to native symbol mapping over a start and end date
@@ -18,23 +20,7 @@ class ProductIdMappingInterval:
1820
The product ID value.
1921
"""
2022

21-
def __init__(
22-
self,
23-
start_date: dt.date,
24-
end_date: dt.date,
25-
native: str,
26-
product_id: int,
27-
):
28-
self.start_date = start_date
29-
self.end_date = end_date
30-
self.native = native
31-
self.product_id = product_id
32-
33-
def __repr__(self):
34-
return (
35-
f"{type(self).__name__}("
36-
f"start_date={self.start_date}, "
37-
f"end_date={self.end_date}, "
38-
f"native='{self.native}', "
39-
f"product_id={self.product_id})"
40-
)
23+
start_date: dt.date
24+
end_date: dt.date
25+
native: str
26+
product_id: int

databento/historical/api/batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BatchHttpAPI(BentoHttpAPI):
2626
Provides request methods for the batch HTTP API endpoints.
2727
"""
2828

29-
def __init__(self, key, gateway):
29+
def __init__(self, key: str, gateway: str) -> None:
3030
super().__init__(key=key, gateway=gateway)
3131
self._base_url = gateway + f"/v{API_VERSION}/batch"
3232

databento/historical/api/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MetadataHttpAPI(BentoHttpAPI):
2121
Provides request methods for the metadata HTTP API endpoints.
2222
"""
2323

24-
def __init__(self, key, gateway):
24+
def __init__(self, key: str, gateway: str) -> None:
2525
super().__init__(key=key, gateway=gateway)
2626
self._base_url = gateway + f"/v{API_VERSION}/metadata"
2727

databento/historical/api/symbology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SymbologyHttpAPI(BentoHttpAPI):
1414
Provides request methods for the symbology HTTP API endpoints.
1515
"""
1616

17-
def __init__(self, key, gateway):
17+
def __init__(self, key: str, gateway: str) -> None:
1818
super().__init__(key=key, gateway=gateway)
1919
self._base_url = gateway + f"/v{API_VERSION}/symbology"
2020

databento/historical/api/timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TimeSeriesHttpAPI(BentoHttpAPI):
1515
Provides request methods for the time series HTTP API endpoints.
1616
"""
1717

18-
def __init__(self, key, gateway):
18+
def __init__(self, key: str, gateway: str) -> None:
1919
super().__init__(key=key, gateway=gateway)
2020
self._base_url = gateway + f"/v{API_VERSION}/timeseries"
2121

databento/historical/error.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Any, Dict, Optional, Union
2+
3+
14
class BentoError(Exception):
25
"""
36
Represents a Databento specific error.
@@ -13,18 +16,18 @@ class BentoHttpError(BentoError):
1316

1417
def __init__(
1518
self,
16-
http_status=None,
17-
http_body=None,
18-
json_body=None,
19-
message=None,
20-
headers=None,
21-
):
19+
http_status: int,
20+
http_body: Optional[Union[bytes, str]] = None,
21+
json_body: Optional[Dict[str, Any]] = None,
22+
message: Optional[str] = None,
23+
headers: Optional[Any] = None,
24+
) -> None:
2225
super(BentoHttpError, self).__init__(message)
2326

24-
if http_body and hasattr(http_body, "decode"):
27+
if http_body and isinstance(http_body, bytes):
2528
try:
2629
http_body = http_body.decode("utf-8")
27-
except BaseException:
30+
except UnicodeDecodeError:
2831
http_body = (
2932
"<Could not decode body as utf-8. "
3033
"Please report to [email protected]>"
@@ -37,15 +40,15 @@ def __init__(
3740
self.headers = headers or {}
3841
self.request_id = self.headers.get("request-id", None)
3942

40-
def __str__(self):
43+
def __str__(self) -> str:
4144
msg = self.message or "<empty message>"
4245
msg = f"{self.http_status} {msg}"
4346
if self.request_id is not None:
4447
return f"Request {self.request_id}: {msg}"
4548
else:
4649
return msg
4750

48-
def __repr__(self):
51+
def __repr__(self) -> str:
4952
return (
5053
f"{type(self).__name__}("
5154
f"request_id={self.request_id}, "
@@ -61,15 +64,15 @@ class BentoServerError(BentoHttpError):
6164

6265
def __init__(
6366
self,
64-
http_status=None,
65-
http_body=None,
66-
json_body=None,
67-
message=None,
68-
headers=None,
69-
):
67+
http_status: int,
68+
http_body: Optional[Union[bytes, str]] = None,
69+
json_body: Optional[Dict[str, Any]] = None,
70+
message: Optional[str] = None,
71+
headers: Optional[Any] = None,
72+
) -> None:
7073
super().__init__(
71-
http_body=http_body,
7274
http_status=http_status,
75+
http_body=http_body,
7376
json_body=json_body,
7477
message=message,
7578
headers=headers,
@@ -83,15 +86,15 @@ class BentoClientError(BentoHttpError):
8386

8487
def __init__(
8588
self,
86-
http_status=None,
87-
http_body=None,
88-
json_body=None,
89-
message=None,
90-
headers=None,
91-
):
89+
http_status: int,
90+
http_body: Optional[Union[bytes, str]] = None,
91+
json_body: Optional[Dict[str, Any]] = None,
92+
message: Optional[str] = None,
93+
headers: Optional[Any] = None,
94+
) -> None:
9295
super().__init__(
93-
http_body=http_body,
9496
http_status=http_status,
97+
http_body=http_body,
9598
json_body=json_body,
9699
message=message,
97100
headers=headers,

0 commit comments

Comments
 (0)