Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f87518

Browse files
oschwaldclaude
andcommitted
Improve type annotations for Record types and Decoder
Convert RecordList and RecordDict from class-based type definitions toexplicit TypeAlias declarations. These types are only used for typeannotations and were never instantiated as actual classes, so usingTypeAlias makes their purpose more explicit and follows modern Pythontyping conventions.Add explicit type annotation to Decoder._type_decoder ClassVar. Thisprovides better type checking for the decoder function map by fullyspecifying the callable signature.These are internal changes with no user-visible effects.🤖 Generated with [Claude Code](https://claude.com/claude-code)Co-Authored-By: Claude <noreply@anthropic.com>
1 parent53101d0 commit9f87518

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎maxminddb/decoder.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
exceptImportError:
1111
mmap=None# type: ignore[assignment]
1212

13-
1413
frommaxminddb.errorsimportInvalidDatabaseError
1514

1615
ifTYPE_CHECKING:
16+
fromcollections.abcimportCallable
17+
1718
frommaxminddb.fileimportFileBuffer
1819
frommaxminddb.typesimportRecord
1920

21+
DecoderFunc=Callable[["Decoder",int,int],tuple[Record,int]]
22+
2023

2124
classDecoder:
2225
"""Decoder for the data section of the MaxMind DB."""
@@ -118,7 +121,7 @@ def _decode_utf8_string(self, size: int, offset: int) -> tuple[str, int]:
118121
new_offset=offset+size
119122
returnself._buffer[offset:new_offset].decode("utf-8"),new_offset
120123

121-
_type_decoder:ClassVar= {
124+
_type_decoder:ClassVar[dict[int,DecoderFunc]]= {
122125
1:_decode_pointer,
123126
2:_decode_utf8_string,
124127
3:_decode_double,

‎maxminddb/types.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66

77
Primitive:TypeAlias=AnyStr|bool|float|int
88

9+
RecordList:TypeAlias=list["Record"]
10+
"""RecordList is a type for lists in a database record."""
911

10-
classRecordList(list["Record"]):
11-
"""RecordList is a type for lists in a database record."""
12-
13-
14-
classRecordDict(dict[str,"Record"]):
15-
"""RecordDict is a type for dicts in a database record."""
16-
12+
RecordDict:TypeAlias=dict[str,"Record"]
13+
"""RecordDict is a type for dicts in a database record."""
1714

1815
Record:TypeAlias=Primitive|RecordList|RecordDict

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp