Skip to content

Commit

Permalink
fix some type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Jul 2, 2024
1 parent c44d4c1 commit 254f907
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
25 changes: 22 additions & 3 deletions aiokafka/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
import threading
import time
from concurrent.futures import Future
from typing import Any, Callable, Dict, Iterable, Optional, Set, Tuple, Union, cast
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Set,
Tuple,
Union,
cast,
)

from typing_extensions import TypeAlias, TypedDict

Expand Down Expand Up @@ -290,10 +301,18 @@ def update_metadata(

for topic_data in metadata.topics:
if isinstance(metadata, MetadataResponse_v0):
error_code, topic, partitions = topic_data
error_code, topic, partitions = cast(
Tuple[int, str, List[Tuple[int, int, int, List[int], List[int]]]],
topic_data,
)
is_internal = False
else:
error_code, topic, is_internal, partitions = topic_data
error_code, topic, is_internal, partitions = cast(
Tuple[
int, str, bool, List[Tuple[int, int, int, List[int], List[int]]]
],
topic_data,
)
if is_internal:
_new_internal_topics.add(topic)
error_type = Errors.for_code(error_code)
Expand Down
49 changes: 18 additions & 31 deletions aiokafka/protocol/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence, Tuple
from typing import List, Tuple

from .api import Request, Response
from .types import Array, Boolean, Int16, Int32, Schema, String
Expand Down Expand Up @@ -31,10 +31,8 @@ class MetadataResponse_v0(Response):
),
)

brokers: Sequence[Tuple[int, str, int]]
topics: Sequence[
Tuple[int, str, Sequence[Tuple[int, int, int, Sequence[int], Sequence[int]]]]
]
brokers: List[Tuple[int, str, int]]
topics: List[Tuple[int, str, List[Tuple[int, int, int, List[int], List[int]]]]]


class MetadataResponse_v1(Response):
Expand Down Expand Up @@ -71,12 +69,10 @@ class MetadataResponse_v1(Response):
),
)

brokers: Sequence[Tuple[int, str, int, str]]
brokers: List[Tuple[int, str, int, str]]
controller_id: int
topics: Sequence[
Tuple[
int, str, bool, Sequence[Tuple[int, int, int, Sequence[int], Sequence[int]]]
]
topics: List[
Tuple[int, str, bool, List[Tuple[int, int, int, List[int], List[int]]]]
]


Expand Down Expand Up @@ -115,13 +111,11 @@ class MetadataResponse_v2(Response):
),
)

brokers: Sequence[Tuple[int, str, int, str]]
brokers: List[Tuple[int, str, int, str]]
cluster_id: str
controller_id: int
topics: Sequence[
Tuple[
int, str, bool, Sequence[Tuple[int, int, int, Sequence[int], Sequence[int]]]
]
topics: List[
Tuple[int, str, bool, List[Tuple[int, int, int, List[int], List[int]]]]
]


Expand Down Expand Up @@ -162,13 +156,11 @@ class MetadataResponse_v3(Response):
)

throttle_time_ms: int
brokers: Sequence[Tuple[int, str, int, str]]
brokers: List[Tuple[int, str, int, str]]
cluster_id: str
controller_id: int
topics: Sequence[
Tuple[
int, str, bool, Sequence[Tuple[int, int, int, Sequence[int], Sequence[int]]]
]
topics: List[
Tuple[int, str, bool, List[Tuple[int, int, int, List[int], List[int]]]]
]


Expand All @@ -178,13 +170,11 @@ class MetadataResponse_v4(Response):
SCHEMA = MetadataResponse_v3.SCHEMA

throttle_time_ms: int
brokers: Sequence[Tuple[int, str, int, str]]
brokers: List[Tuple[int, str, int, str]]
cluster_id: str
controller_id: int
topics: Sequence[
Tuple[
int, str, bool, Sequence[Tuple[int, int, int, Sequence[int], Sequence[int]]]
]
topics: List[
Tuple[int, str, bool, List[Tuple[int, int, int, List[int], List[int]]]]
]


Expand Down Expand Up @@ -226,15 +216,12 @@ class MetadataResponse_v5(Response):
)

throttle_time_ms: int
brokers: Sequence[Tuple[int, str, int, str]]
brokers: List[Tuple[int, str, int, str]]
cluster_id: str
controller_id: int
topics: Sequence[
topics: List[
Tuple[
int,
str,
bool,
Sequence[Tuple[int, int, int, Sequence[int], Sequence[int], Sequence[int]]],
int, str, bool, List[Tuple[int, int, int, List[int], List[int], List[int]]]
]
]

Expand Down

0 comments on commit 254f907

Please sign in to comment.