Skip to content

Commit a8a403c

Browse files
committed
Use modern union syntax throughout
1 parent a6dbd78 commit a8a403c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

maxminddb/decoder.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Decoder for the MaxMind DB data section."""
22

3+
from __future__ import annotations
4+
35
import struct
4-
from typing import ClassVar, Union, cast
6+
from typing import TYPE_CHECKING, ClassVar, cast
57

68
try:
79
import mmap
@@ -10,16 +12,18 @@
1012

1113

1214
from maxminddb.errors import InvalidDatabaseError
13-
from maxminddb.file import FileBuffer
14-
from maxminddb.types import Record
15+
16+
if TYPE_CHECKING:
17+
from maxminddb.file import FileBuffer
18+
from maxminddb.types import Record
1519

1620

1721
class Decoder:
1822
"""Decoder for the data section of the MaxMind DB."""
1923

2024
def __init__(
2125
self,
22-
database_buffer: Union[FileBuffer, "mmap.mmap", bytes],
26+
database_buffer: FileBuffer | mmap.mmap | bytes,
2327
pointer_base: int = 0,
2428
pointer_test: bool = False, # noqa: FBT001, FBT002
2529
) -> None:

maxminddb/types.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
"""Types representing database records."""
22

3-
from typing import AnyStr, Union
3+
from __future__ import annotations
44

5-
Primitive = Union[AnyStr, bool, float, int]
6-
Record = Union[Primitive, "RecordList", "RecordDict"]
5+
from typing import AnyStr, TypeAlias
76

7+
Primitive: TypeAlias = AnyStr | bool | float | int
88

9-
class RecordList(list[Record]):
9+
10+
class RecordList(list["Record"]):
1011
"""RecordList is a type for lists in a database record."""
1112

1213

13-
class RecordDict(dict[str, Record]):
14+
class RecordDict(dict[str, "Record"]):
1415
"""RecordDict is a type for dicts in a database record."""
16+
17+
18+
Record: TypeAlias = Primitive | RecordList | RecordDict

0 commit comments

Comments
 (0)