Skip to content

Commit b41ff85

Browse files
committed
Improve typing of database records
1 parent 987c956 commit b41ff85

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

maxminddb/reader.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,7 @@
2323
from maxminddb.decoder import Decoder
2424
from maxminddb.errors import InvalidDatabaseError
2525
from maxminddb.file import FileBuffer
26-
27-
Record = Union[
28-
str,
29-
Dict[str, str],
30-
Dict[
31-
str,
32-
Union[
33-
List[int],
34-
bytes,
35-
float,
36-
int,
37-
Dict[str, Dict[str, Union[List[int], str]]],
38-
str,
39-
],
40-
],
41-
]
26+
from maxminddb.types import Record
4227

4328

4429
class Reader:

maxminddb/types.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
maxminddb.types
3+
~~~~~~~~~~~~~~~
4+
5+
This module provides a Record type the represents a database record.
6+
"""
7+
from typing import AnyStr, Dict, List, Union
8+
9+
Primitive = Union[AnyStr, bool, float, int]
10+
Record = Union[Primitive, "RecordList", "RecordDict"]
11+
12+
13+
class RecordList(List[Record]): # pylint: disable=too-few-public-methods
14+
"""
15+
RecordList is a type for lists in a database record.
16+
"""
17+
18+
19+
class RecordDict(Dict[str, Record]): # pylint: disable=too-few-public-methods
20+
"""
21+
RecordDict is a type for dicts in a database record.
22+
"""

0 commit comments

Comments
 (0)