Skip to content

Commit f756116

Browse files
committed
address mypy complaints
1 parent c28e856 commit f756116

File tree

16 files changed

+171
-124
lines changed

16 files changed

+171
-124
lines changed

src/confluent_kafka/_types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
from typing import Any, Optional, Dict, Union, Callable, List, Tuple
2727

28-
# Configuration dictionary type
29-
ConfigDict = Dict[str, Union[str, int, float, bool]]
30-
3128
# Headers can be either dict format or list of tuples format
3229
HeadersType = Union[
3330
Dict[str, Union[str, bytes, None]],

src/confluent_kafka/_util/validation_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ..cimpl import KafkaError
1717

1818
try:
19-
string_type = basestring
19+
string_type = basestring # type: ignore[name-defined]
2020
except NameError:
2121
string_type = str
2222

src/confluent_kafka/admin/__init__.py

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@
8787
ConsumerGroupState as _ConsumerGroupState, \
8888
IsolationLevel as _IsolationLevel
8989

90-
from .._types import ConfigDict
91-
9290

9391
try:
94-
string_type = basestring
92+
string_type = basestring # type: ignore[name-defined]
9593
except NameError:
9694
string_type = str
9795

@@ -118,7 +116,7 @@ class AdminClient (_AdminClientImpl):
118116
Requires broker version v0.11.0.0 or later.
119117
"""
120118

121-
def __init__(self, conf: ConfigDict, **kwargs: Any) -> None:
119+
def __init__(self, conf: Dict[str, Union[str, int, float, bool]], **kwargs: Any) -> None:
122120
"""
123121
Create a new AdminClient using the provided configuration dictionary.
124122
@@ -311,7 +309,7 @@ def _make_futmap_result(f: concurrent.futures.Future, futmap: Dict[str, concurre
311309

312310
@staticmethod
313311
def _create_future() -> concurrent.futures.Future:
314-
f = concurrent.futures.Future()
312+
f: concurrent.futures.Future = concurrent.futures.Future()
315313
if not f.set_running_or_notify_cancel():
316314
raise RuntimeError("Future was cancelled prematurely")
317315
return f
@@ -580,7 +578,9 @@ def _check_elect_leaders(election_type: _ElectionType, partitions: Optional[List
580578
raise ValueError("Elements of the 'partitions' list must not have negative value" +
581579
" for 'partition' field")
582580

583-
def create_topics(self, new_topics: List[NewTopic], **kwargs: Any) -> Dict[str, concurrent.futures.Future]:
581+
def create_topics( # type: ignore[override]
582+
self, new_topics: List[NewTopic], **kwargs: Any
583+
) -> Dict[str, concurrent.futures.Future]:
584584
"""
585585
Create one or more new topics.
586586
@@ -615,7 +615,9 @@ def create_topics(self, new_topics: List[NewTopic], **kwargs: Any) -> Dict[str,
615615

616616
return futmap
617617

618-
def delete_topics(self, topics: List[str], **kwargs: Any) -> Dict[str, concurrent.futures.Future]:
618+
def delete_topics( # type: ignore[override]
619+
self, topics: List[str], **kwargs: Any
620+
) -> Dict[str, concurrent.futures.Future]:
619621
"""
620622
Delete one or more topics.
621623
@@ -654,8 +656,9 @@ def list_groups(self, *args: Any, **kwargs: Any) -> GroupMetadata:
654656

655657
return super(AdminClient, self).list_groups(*args, **kwargs)
656658

657-
def create_partitions(self, new_partitions: List[NewPartitions],
658-
**kwargs: Any) -> Dict[str, concurrent.futures.Future]:
659+
def create_partitions( # type: ignore[override]
660+
self, new_partitions: List[NewPartitions], **kwargs: Any
661+
) -> Dict[str, concurrent.futures.Future]:
659662
"""
660663
Create additional partitions for the given topics.
661664
@@ -689,8 +692,9 @@ def create_partitions(self, new_partitions: List[NewPartitions],
689692

690693
return futmap
691694

692-
def describe_configs(self, resources: List[ConfigResource],
693-
**kwargs: Any) -> Dict[ConfigResource, concurrent.futures.Future]:
695+
def describe_configs( # type: ignore[override]
696+
self, resources: List[ConfigResource], **kwargs: Any
697+
) -> Dict[ConfigResource, concurrent.futures.Future]:
694698
"""
695699
Get the configuration of the specified resources.
696700
@@ -722,8 +726,9 @@ def describe_configs(self, resources: List[ConfigResource],
722726

723727
return futmap
724728

725-
def alter_configs(self, resources: List[ConfigResource],
726-
**kwargs: Any) -> Dict[ConfigResource, concurrent.futures.Future]:
729+
def alter_configs( # type: ignore[override]
730+
self, resources: List[ConfigResource], **kwargs: Any
731+
) -> Dict[ConfigResource, concurrent.futures.Future]:
727732
"""
728733
.. deprecated:: 2.2.0
729734
@@ -771,8 +776,9 @@ def alter_configs(self, resources: List[ConfigResource],
771776

772777
return futmap
773778

774-
def incremental_alter_configs(self, resources: List[ConfigResource],
775-
**kwargs: Any) -> Dict[ConfigResource, concurrent.futures.Future]:
779+
def incremental_alter_configs( # type: ignore[override]
780+
self, resources: List[ConfigResource], **kwargs: Any
781+
) -> Dict[ConfigResource, concurrent.futures.Future]:
776782
"""
777783
Update configuration properties for the specified resources.
778784
Updates are incremental, i.e only the values mentioned are changed
@@ -805,7 +811,9 @@ def incremental_alter_configs(self, resources: List[ConfigResource],
805811

806812
return futmap
807813

808-
def create_acls(self, acls: List[AclBinding], **kwargs: Any) -> Dict[AclBinding, concurrent.futures.Future]:
814+
def create_acls( # type: ignore[override]
815+
self, acls: List[AclBinding], **kwargs: Any
816+
) -> Dict[AclBinding, concurrent.futures.Future]:
809817
"""
810818
Create one or more ACL bindings.
811819
@@ -834,7 +842,9 @@ def create_acls(self, acls: List[AclBinding], **kwargs: Any) -> Dict[AclBinding,
834842

835843
return futmap
836844

837-
def describe_acls(self, acl_binding_filter: AclBindingFilter, **kwargs: Any) -> concurrent.futures.Future:
845+
def describe_acls( # type: ignore[override]
846+
self, acl_binding_filter: AclBindingFilter, **kwargs: Any
847+
) -> concurrent.futures.Future:
838848
"""
839849
Match ACL bindings by filter.
840850
@@ -869,8 +879,9 @@ def describe_acls(self, acl_binding_filter: AclBindingFilter, **kwargs: Any) ->
869879

870880
return f
871881

872-
def delete_acls(self, acl_binding_filters: List[AclBindingFilter],
873-
**kwargs: Any) -> Dict[AclBindingFilter, concurrent.futures.Future]:
882+
def delete_acls( # type: ignore[override]
883+
self, acl_binding_filters: List[AclBindingFilter], **kwargs: Any
884+
) -> Dict[AclBindingFilter, concurrent.futures.Future]:
874885
"""
875886
Delete ACL bindings matching one or more ACL binding filters.
876887
@@ -909,7 +920,9 @@ def delete_acls(self, acl_binding_filters: List[AclBindingFilter],
909920

910921
return futmap
911922

912-
def list_consumer_groups(self, **kwargs: Any) -> concurrent.futures.Future:
923+
def list_consumer_groups( # type: ignore[override]
924+
self, **kwargs: Any
925+
) -> concurrent.futures.Future:
913926
"""
914927
List consumer groups.
915928
@@ -956,7 +969,9 @@ def list_consumer_groups(self, **kwargs: Any) -> concurrent.futures.Future:
956969

957970
return f
958971

959-
def describe_consumer_groups(self, group_ids: List[str], **kwargs: Any) -> Dict[str, concurrent.futures.Future]:
972+
def describe_consumer_groups( # type: ignore[override]
973+
self, group_ids: List[str], **kwargs: Any
974+
) -> Dict[str, concurrent.futures.Future]:
960975
"""
961976
Describe consumer groups.
962977
@@ -985,11 +1000,13 @@ def describe_consumer_groups(self, group_ids: List[str], **kwargs: Any) -> Dict[
9851000
f, futmap = AdminClient._make_futures(group_ids, None,
9861001
AdminClient._make_consumer_groups_result)
9871002

988-
super(AdminClient, self).describe_consumer_groups(group_ids, f, **kwargs)
1003+
super(AdminClient, self).describe_consumer_groups(group_ids, f, **kwargs) # type: ignore[arg-type]
9891004

9901005
return futmap
9911006

992-
def describe_topics(self, topics: _TopicCollection, **kwargs: Any) -> Dict[str, concurrent.futures.Future]:
1007+
def describe_topics( # type: ignore[override]
1008+
self, topics: _TopicCollection, **kwargs: Any
1009+
) -> Dict[str, concurrent.futures.Future]:
9931010
"""
9941011
Describe topics.
9951012
@@ -1020,11 +1037,13 @@ def describe_topics(self, topics: _TopicCollection, **kwargs: Any) -> Dict[str,
10201037
f, futmap = AdminClient._make_futures_v2(topic_names, None,
10211038
AdminClient._make_futmap_result_from_list)
10221039

1023-
super(AdminClient, self).describe_topics(topic_names, f, **kwargs)
1040+
super(AdminClient, self).describe_topics(topic_names, f, **kwargs) # type: ignore[arg-type]
10241041

10251042
return futmap
10261043

1027-
def describe_cluster(self, **kwargs: Any) -> concurrent.futures.Future:
1044+
def describe_cluster( # type: ignore[override]
1045+
self, **kwargs: Any
1046+
) -> concurrent.futures.Future:
10281047
"""
10291048
Describe cluster.
10301049
@@ -1048,7 +1067,9 @@ def describe_cluster(self, **kwargs: Any) -> concurrent.futures.Future:
10481067

10491068
return f
10501069

1051-
def delete_consumer_groups(self, group_ids: List[str], **kwargs: Any) -> Dict[str, concurrent.futures.Future]:
1070+
def delete_consumer_groups( # type: ignore[override]
1071+
self, group_ids: List[str], **kwargs: Any
1072+
) -> Dict[str, concurrent.futures.Future]:
10521073
"""
10531074
Delete the given consumer groups.
10541075
@@ -1079,9 +1100,10 @@ def delete_consumer_groups(self, group_ids: List[str], **kwargs: Any) -> Dict[st
10791100

10801101
return futmap
10811102

1082-
def list_consumer_group_offsets(
1083-
self, list_consumer_group_offsets_request: List[_ConsumerGroupTopicPartitions],
1084-
**kwargs: Any) -> Dict[str, concurrent.futures.Future]:
1103+
def list_consumer_group_offsets( # type: ignore[override]
1104+
self, list_consumer_group_offsets_request: List[_ConsumerGroupTopicPartitions],
1105+
**kwargs: Any
1106+
) -> Dict[str, concurrent.futures.Future]:
10851107
"""
10861108
List offset information for the consumer group and (optional) topic partition provided in the request.
10871109
@@ -1118,9 +1140,10 @@ def list_consumer_group_offsets(
11181140

11191141
return futmap
11201142

1121-
def alter_consumer_group_offsets(
1122-
self, alter_consumer_group_offsets_request: List[_ConsumerGroupTopicPartitions],
1123-
**kwargs: Any) -> Dict[str, concurrent.futures.Future]:
1143+
def alter_consumer_group_offsets( # type: ignore[override]
1144+
self, alter_consumer_group_offsets_request: List[_ConsumerGroupTopicPartitions],
1145+
**kwargs: Any
1146+
) -> Dict[str, concurrent.futures.Future]:
11241147
"""
11251148
Alter offset for the consumer group and topic partition provided in the request.
11261149
@@ -1172,9 +1195,9 @@ def set_sasl_credentials(self, username: str, password: str) -> None:
11721195
"""
11731196
super(AdminClient, self).set_sasl_credentials(username, password)
11741197

1175-
def describe_user_scram_credentials(
1176-
self, users: Optional[List[str]] = None,
1177-
**kwargs: Any) -> Union[concurrent.futures.Future, Dict[str, concurrent.futures.Future]]:
1198+
def describe_user_scram_credentials( # type: ignore[override]
1199+
self, users: Optional[List[str]] = None, **kwargs: Any
1200+
) -> Union[concurrent.futures.Future, Dict[str, concurrent.futures.Future]]:
11781201
"""
11791202
Describe user SASL/SCRAM credentials.
11801203
@@ -1205,14 +1228,14 @@ def describe_user_scram_credentials(
12051228
if users is None:
12061229
internal_f, ret_fut = AdminClient._make_single_future_pair()
12071230
else:
1208-
internal_f, ret_fut = AdminClient._make_futures_v2(
1231+
internal_f, ret_fut = AdminClient._make_futures_v2( # type: ignore[assignment]
12091232
users, None, AdminClient._make_futmap_result)
12101233
super(AdminClient, self).describe_user_scram_credentials(users, internal_f, **kwargs)
12111234
return ret_fut
12121235

1213-
def alter_user_scram_credentials(
1214-
self, alterations: List[UserScramCredentialAlteration],
1215-
**kwargs: Any) -> Dict[str, concurrent.futures.Future]:
1236+
def alter_user_scram_credentials( # type: ignore[override]
1237+
self, alterations: List[UserScramCredentialAlteration], **kwargs: Any
1238+
) -> Dict[str, concurrent.futures.Future]:
12161239
"""
12171240
Alter user SASL/SCRAM credentials.
12181241
@@ -1241,8 +1264,9 @@ def alter_user_scram_credentials(
12411264
super(AdminClient, self).alter_user_scram_credentials(alterations, f, **kwargs)
12421265
return futmap
12431266

1244-
def list_offsets(self, topic_partition_offsets: Dict[_TopicPartition, OffsetSpec],
1245-
**kwargs: Any) -> Dict[_TopicPartition, concurrent.futures.Future]:
1267+
def list_offsets( # type: ignore[override]
1268+
self, topic_partition_offsets: Dict[_TopicPartition, OffsetSpec], **kwargs: Any
1269+
) -> Dict[_TopicPartition, concurrent.futures.Future]:
12461270
"""
12471271
Enables to find the beginning offset,
12481272
end offset as well as the offset matching a timestamp
@@ -1283,8 +1307,9 @@ def list_offsets(self, topic_partition_offsets: Dict[_TopicPartition, OffsetSpec
12831307
super(AdminClient, self).list_offsets(topic_partition_offsets_list, f, **kwargs)
12841308
return futmap
12851309

1286-
def delete_records(self, topic_partition_offsets: List[_TopicPartition],
1287-
**kwargs: Any) -> Dict[_TopicPartition, concurrent.futures.Future]:
1310+
def delete_records( # type: ignore[override]
1311+
self, topic_partition_offsets: List[_TopicPartition], **kwargs: Any
1312+
) -> Dict[_TopicPartition, concurrent.futures.Future]:
12881313
"""
12891314
Deletes all the records before the specified offsets (not including),
12901315
in the specified topics and partitions.
@@ -1321,9 +1346,10 @@ def delete_records(self, topic_partition_offsets: List[_TopicPartition],
13211346
super(AdminClient, self).delete_records(topic_partition_offsets, f, **kwargs)
13221347
return futmap
13231348

1324-
def elect_leaders(self, election_type: _ElectionType,
1325-
partitions: Optional[List[_TopicPartition]] = None,
1326-
**kwargs: Any) -> concurrent.futures.Future:
1349+
def elect_leaders( # type: ignore[override]
1350+
self, election_type: _ElectionType, partitions: Optional[List[_TopicPartition]] = None,
1351+
**kwargs: Any
1352+
) -> concurrent.futures.Future:
13271353
"""
13281354
Perform Preferred or Unclean leader election for
13291355
all the specified partitions or all partitions in the cluster.

src/confluent_kafka/admin/_acl.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .._util import ValidationUtil, ConversionUtil
2222

2323
try:
24-
string_type = basestring
24+
string_type = basestring # type: ignore[name-defined]
2525
except NameError:
2626
string_type = str
2727

@@ -104,19 +104,19 @@ def __init__(self, restype: Union[ResourceType, str, int], name: str,
104104
self.permission_type = permission_type
105105
self._convert_args()
106106
# for the C code
107-
self.restype_int = int(self.restype.value)
108-
self.resource_pattern_type_int = int(self.resource_pattern_type.value)
109-
self.operation_int = int(self.operation.value)
110-
self.permission_type_int = int(self.permission_type.value)
107+
self.restype_int = int(self.restype.value) # type: ignore[union-attr]
108+
self.resource_pattern_type_int = int(self.resource_pattern_type.value) # type: ignore[union-attr]
109+
self.operation_int = int(self.operation.value) # type: ignore[union-attr]
110+
self.permission_type_int = int(self.permission_type.value) # type: ignore[union-attr]
111111

112112
def _convert_enums(self) -> None:
113-
self.restype = ConversionUtil.convert_to_enum(self.restype, ResourceType)
113+
self.restype = ConversionUtil.convert_to_enum(self.restype, ResourceType) # type: ignore[assignment]
114114
self.resource_pattern_type = ConversionUtil.convert_to_enum(
115-
self.resource_pattern_type, ResourcePatternType)
115+
self.resource_pattern_type, ResourcePatternType) # type: ignore[assignment]
116116
self.operation = ConversionUtil.convert_to_enum(
117-
self.operation, AclOperation)
117+
self.operation, AclOperation) # type: ignore[assignment]
118118
self.permission_type = ConversionUtil.convert_to_enum(
119-
self.permission_type, AclPermissionType)
119+
self.permission_type, AclPermissionType) # type: ignore[assignment]
120120

121121
def _check_forbidden_enums(self, forbidden_enums: Dict[str, List[Enum]]) -> None:
122122
for k, v in forbidden_enums.items():
@@ -154,7 +154,7 @@ def __repr__(self) -> str:
154154
return "%s(%s,%s,%s,%s,%s,%s,%s)" % ((type_name,) + self._to_tuple())
155155

156156
def _to_tuple(self) -> Tuple[ResourceType, str, ResourcePatternType, str, str, AclOperation, AclPermissionType]:
157-
return (self.restype, self.name, self.resource_pattern_type,
157+
return (self.restype, self.name, self.resource_pattern_type, # type: ignore[return-value]
158158
self.principal, self.host, self.operation,
159159
self.permission_type)
160160

@@ -166,8 +166,8 @@ def __lt__(self, other: 'AclBinding') -> Any:
166166
return NotImplemented
167167
return self._to_tuple() < other._to_tuple()
168168

169-
def __eq__(self, other: 'AclBinding') -> Any:
170-
if self.__class__ != other.__class__:
169+
def __eq__(self, other: object) -> Any:
170+
if not isinstance(other, AclBinding):
171171
return NotImplemented
172172
return self._to_tuple() == other._to_tuple()
173173

src/confluent_kafka/admin/_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def __lt__(self, other: 'ConfigResource') -> bool:
190190
return True
191191
return self.name.__lt__(other.name)
192192

193-
def __eq__(self, other: 'ConfigResource') -> bool:
193+
def __eq__(self, other: object) -> bool:
194+
if not isinstance(other, ConfigResource):
195+
return NotImplemented
194196
return self.restype == other.restype and self.name == other.name
195197

196198
def __len__(self) -> int:

0 commit comments

Comments
 (0)