Skip to content

Commit b490d49

Browse files
committed
Ensure stubtests for kafka-python passes
1 parent 6696b3e commit b490d49

13 files changed

Lines changed: 67 additions & 31 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Command-line entry points are not a useful typed API surface.
2+
kafka.__main__
3+
kafka.admin.__main__
4+
kafka.consumer.__main__
5+
kafka.producer.__main__
6+
7+
# Concrete subclasses define these abstract properties as class attributes.
8+
kafka.protocol.api.Request.API_KEY
9+
kafka.protocol.api.Request.API_VERSION
10+
kafka.protocol.api.Request.RESPONSE_TYPE
11+
kafka.protocol.api.Request.SCHEMA
12+
kafka.protocol.api.Response.API_KEY
13+
kafka.protocol.api.Response.API_VERSION
14+
kafka.protocol.api.Response.SCHEMA
15+
16+
# Vendored compatibility modules are implementation details.
17+
kafka.vendor
18+
kafka.vendor.enum34
19+
kafka.vendor.selectors34
20+
kafka.vendor.six
21+
kafka.vendor.socketpair

stubs/kafka-python/METADATA.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
version = "2.3.*"
22
upstream-repository = "https://github.com/dpkp/kafka-python"
3+
4+
[tool.stubtest]
5+
stubtest-dependencies = ["pyperf"]

stubs/kafka-python/kafka/admin/client.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import selectors
22
import ssl
33
from _typeshed import Incomplete
44
from collections.abc import Callable, Iterable, Mapping, Sequence
5-
from typing import Literal, TypeAlias, TypedDict
5+
from typing import Literal, TypeAlias, TypedDict, type_check_only
66
from typing_extensions import Unpack
77

88
from kafka.admin.acl_resource import ACL, ACLFilter
@@ -20,6 +20,7 @@ _SaslMechanism: TypeAlias = Literal["PLAIN", "GSSAPI", "OAUTHBEARER", "SCRAM-SHA
2020
_SecurityProtocol: TypeAlias = Literal["PLAINTEXT", "SSL", "SASL_PLAINTEXT", "SASL_SSL"]
2121
_SocketOption: TypeAlias = tuple[int, int, int]
2222

23+
@type_check_only
2324
class _KafkaAdminClientConfig(TypedDict, total=False):
2425
bootstrap_servers: _BootstrapServers
2526
client_id: str
@@ -59,6 +60,7 @@ class _KafkaAdminClientConfig(TypedDict, total=False):
5960
metrics_sample_window_ms: int
6061
kafka_client: _KafkaClientFactory
6162

63+
@type_check_only
6264
class _CreateAclsResult(TypedDict):
6365
succeeded: list[ACL]
6466
failed: list[tuple[ACL, KafkaError]]

stubs/kafka-python/kafka/client_async.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from _typeshed import Incomplete
2+
from collections import OrderedDict as OrderedDict
23

34
log: Incomplete
45
socketpair: Incomplete
@@ -33,8 +34,6 @@ class KafkaClient:
3334
def await_ready(self, node_id, timeout_ms: int = 30000): ...
3435
def send_and_receive(self, node_id, request): ...
3536

36-
OrderedDict = dict
37-
3837
class IdleConnectionManager:
3938
connections_max_idle: Incomplete
4039
next_idle_close_check_time: Incomplete

stubs/kafka-python/kafka/consumer/fetcher.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from _typeshed import Incomplete
2-
from typing import NamedTuple
2+
from typing import ClassVar, NamedTuple
33

44
import kafka.errors as Errors
55

@@ -99,6 +99,8 @@ class FetchMetadata:
9999
THROTTLED_SESSION_ID: int
100100
INITIAL_EPOCH: int
101101
FINAL_EPOCH: int
102+
INITIAL: ClassVar[FetchMetadata]
103+
LEGACY: ClassVar[FetchMetadata]
102104
session_id: Incomplete
103105
epoch: Incomplete
104106
def __init__(self, session_id, epoch) -> None: ...

stubs/kafka-python/kafka/consumer/group.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import selectors
22
import ssl
33
from _typeshed import Incomplete
44
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
5-
from typing import Literal, TypeAlias, TypedDict, overload
5+
from typing import Literal, TypeAlias, TypedDict, overload, type_check_only
66
from typing_extensions import Self, Unpack
77

88
from kafka.consumer.fetcher import ConsumerRecord
@@ -20,6 +20,7 @@ _SaslMechanism: TypeAlias = Literal["PLAIN", "GSSAPI", "OAUTHBEARER", "SCRAM-SHA
2020
_SecurityProtocol: TypeAlias = Literal["PLAINTEXT", "SSL", "SASL_PLAINTEXT", "SASL_SSL"]
2121
_SocketOption: TypeAlias = tuple[int, int, int]
2222

23+
@type_check_only
2324
class _KafkaConsumerConfig(TypedDict, total=False):
2425
bootstrap_servers: _BootstrapServers
2526
client_id: str

stubs/kafka-python/kafka/coordinator/base.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
import threading
33
from _typeshed import Incomplete
4+
from typing import ClassVar
45

56
from kafka import errors as Errors
67

@@ -13,6 +14,7 @@ class MemberState:
1314
STABLE: str
1415

1516
class Generation:
17+
NO_GENERATION: ClassVar[Generation]
1618
generation_id: Incomplete
1719
member_id: Incomplete
1820
protocol: Incomplete

stubs/kafka-python/kafka/producer/kafka.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import selectors
22
import ssl
33
from _typeshed import Incomplete
44
from collections.abc import Callable, Mapping, Sequence
5-
from typing import Literal, TypeAlias, TypedDict
5+
from typing import Literal, TypeAlias, TypedDict, type_check_only
66
from typing_extensions import Unpack
77

88
from kafka.producer.future import FutureRecordMetadata
@@ -18,6 +18,7 @@ _SaslMechanism: TypeAlias = Literal["PLAIN", "GSSAPI", "OAUTHBEARER", "SCRAM-SHA
1818
_SecurityProtocol: TypeAlias = Literal["PLAINTEXT", "SSL", "SASL_PLAINTEXT", "SASL_SSL"]
1919
_SocketOption: TypeAlias = tuple[int, int, int]
2020

21+
@type_check_only
2122
class _KafkaProducerConfig(TypedDict, total=False):
2223
bootstrap_servers: _BootstrapServers
2324
client_id: str | None

stubs/kafka-python/kafka/producer/sender.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ from typing import NamedTuple
55
log: Incomplete
66

77
class PartitionResponse(NamedTuple):
8-
error: Incomplete
9-
base_offset: Incomplete
10-
last_offset: Incomplete
11-
log_append_time: Incomplete
12-
log_start_offset: Incomplete
13-
record_errors: Incomplete
14-
error_message: Incomplete
15-
current_leader: Incomplete
8+
error: Incomplete = ...
9+
base_offset: Incomplete = ...
10+
last_offset: Incomplete = ...
11+
log_append_time: Incomplete = ...
12+
log_start_offset: Incomplete = ...
13+
record_errors: Incomplete = ...
14+
error_message: Incomplete = ...
15+
current_leader: Incomplete = ...
1616

1717
class Sender(threading.Thread):
1818
DEFAULT_CONFIG: Incomplete

stubs/kafka-python/kafka/protocol/group.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ DEFAULT_GENERATION_ID: int
88
UNKNOWN_MEMBER_ID: str
99

1010
class GroupMember(NamedTuple):
11-
member_id: Incomplete
12-
group_instance_id: Incomplete
13-
metadata_bytes: Incomplete
11+
member_id: Incomplete = ...
12+
group_instance_id: Incomplete = ...
13+
metadata_bytes: Incomplete = ...
1414

1515
class JoinGroupResponse_v0(Response):
1616
API_KEY: int

0 commit comments

Comments
 (0)