Skip to content

Commit d789244

Browse files
committed
admin
1 parent 69ca6b8 commit d789244

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

src/confluent_kafka/_model/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Optional
15+
from typing import List, Optional, Any
1616
from enum import Enum
1717
from .. import cimpl
1818
from ..cimpl import TopicPartition
@@ -62,7 +62,7 @@ class ConsumerGroupTopicPartitions:
6262
List of topic partitions information.
6363
"""
6464

65-
def __init__(self, group_id: str, topic_partitions: Optional[List[TopicPartition]] = None) -> None:
65+
def __init__(self, group_id: str, topic_partitions: Optional[List['cimpl.TopicPartition']] = None) -> None:
6666
self.group_id = group_id
6767
self.topic_partitions = topic_partitions
6868

@@ -91,8 +91,8 @@ class ConsumerGroupState(Enum):
9191
#: Consumer Group is empty.
9292
EMPTY = cimpl.CONSUMER_GROUP_STATE_EMPTY
9393

94-
def __lt__(self, other: object) -> bool:
95-
if not isinstance(other, ConsumerGroupState):
94+
def __lt__(self, other: 'ConsumerGroupState') -> Any:
95+
if self.__class__ != other.__class__:
9696
return NotImplemented
9797
return self.value < other.value
9898

@@ -111,8 +111,8 @@ class ConsumerGroupType(Enum):
111111
#: Classic Type
112112
CLASSIC = cimpl.CONSUMER_GROUP_TYPE_CLASSIC
113113

114-
def __lt__(self, other: object) -> bool:
115-
if not isinstance(other, ConsumerGroupType):
114+
def __lt__(self, other: 'ConsumerGroupType') -> Any:
115+
if self.__class__ != other.__class__:
116116
return NotImplemented
117117
return self.value < other.value
118118

@@ -167,8 +167,8 @@ class IsolationLevel(Enum):
167167
READ_UNCOMMITTED = cimpl.ISOLATION_LEVEL_READ_UNCOMMITTED #: Receive all the offsets.
168168
READ_COMMITTED = cimpl.ISOLATION_LEVEL_READ_COMMITTED #: Skip offsets belonging to an aborted transaction.
169169

170-
def __lt__(self, other: object) -> bool:
171-
if not isinstance(other, IsolationLevel):
170+
def __lt__(self, other: 'IsolationLevel') -> Any:
171+
if self.__class__ != other.__class__:
172172
return NotImplemented
173173
return self.value < other.value
174174

@@ -186,7 +186,7 @@ class ElectionType(Enum):
186186
#: Unclean election
187187
UNCLEAN = cimpl.ELECTION_TYPE_UNCLEAN
188188

189-
def __lt__(self, other: object) -> bool:
190-
if not isinstance(other, ElectionType):
189+
def __lt__(self, other: 'ElectionType') -> Any:
190+
if self.__class__ != other.__class__:
191191
return NotImplemented
192192
return self.value < other.value

src/confluent_kafka/_util/conversion_util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Union, Type
15+
from typing import Union, Type, TypeVar
1616
from enum import Enum
1717

18+
# Generic type for enum conversion
19+
E = TypeVar('E', bound=Enum)
20+
1821

1922
class ConversionUtil:
2023
@staticmethod
21-
def convert_to_enum(val: Union[str, int, Enum], enum_clazz: Type[Enum]) -> Enum:
24+
def convert_to_enum(val: Union[str, int, E], enum_clazz: Type[E]) -> E:
2225
if type(enum_clazz) is not type(Enum):
2326
raise TypeError("'enum_clazz' must be of type Enum")
2427

src/confluent_kafka/admin/_cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, controller: Node, nodes: List[Node], cluster_id: Optional[str
4141
self.cluster_id = cluster_id
4242
self.controller = controller
4343
self.nodes = nodes
44-
self.authorized_operations = None
44+
self.authorized_operations: Optional[List[AclOperation]] = None
4545
if authorized_operations:
4646
self.authorized_operations = []
4747
for op in authorized_operations:

src/confluent_kafka/admin/_resource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class ResourceType(Enum):
2828
BROKER = _cimpl.RESOURCE_BROKER #: Broker resource. Resource name is broker id.
2929
TRANSACTIONAL_ID = _cimpl.RESOURCE_TRANSACTIONAL_ID #: Transactional ID resource.
3030

31-
def __lt__(self, other: object) -> Any:
32-
if not isinstance(other, ResourceType):
31+
def __lt__(self, other: 'ResourceType') -> Any:
32+
if self.__class__ != other.__class__:
3333
return NotImplemented
3434
return self.value < other.value
3535

@@ -44,7 +44,7 @@ class ResourcePatternType(Enum):
4444
LITERAL = _cimpl.RESOURCE_PATTERN_LITERAL #: Literal: A literal resource name
4545
PREFIXED = _cimpl.RESOURCE_PATTERN_PREFIXED #: Prefixed: A prefixed resource name
4646

47-
def __lt__(self, other: object) -> Any:
48-
if not isinstance(other, ResourcePatternType):
47+
def __lt__(self, other: 'ResourcePatternType') -> Any:
48+
if self.__class__ != other.__class__:
4949
return NotImplemented
5050
return self.value < other.value

src/confluent_kafka/admin/_scram.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Optional
15+
from typing import List, Optional, Any
1616
from enum import Enum
1717

1818
from .. import cimpl
@@ -26,8 +26,8 @@ class ScramMechanism(Enum):
2626
SCRAM_SHA_256 = cimpl.SCRAM_MECHANISM_SHA_256 #: SCRAM-SHA-256 mechanism
2727
SCRAM_SHA_512 = cimpl.SCRAM_MECHANISM_SHA_512 #: SCRAM-SHA-512 mechanism
2828

29-
def __lt__(self, other: object) -> bool:
30-
if not isinstance(other, ScramMechanism):
29+
def __lt__(self, other: 'ScramMechanism') -> Any:
30+
if self.__class__ != other.__class__:
3131
return NotImplemented
3232
return self.value < other.value
3333

src/confluent_kafka/admin/_topic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, name: str, topic_id: Uuid, is_internal: bool,
4646
self.topic_id = topic_id
4747
self.is_internal = is_internal
4848
self.partitions = partitions
49-
self.authorized_operations = None
49+
self.authorized_operations: Optional[List[AclOperation]] = None
5050
if authorized_operations:
5151
self.authorized_operations = []
5252
for op in authorized_operations:

src/confluent_kafka/deserializing_consumer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
#
1818

19-
from typing import Any, Optional, Callable, List
19+
from typing import Optional, List
2020

2121
from confluent_kafka.cimpl import Consumer as _ConsumerImpl, Message
2222
from .error import (ConsumeError,
@@ -80,7 +80,7 @@ def __init__(self, conf: ConfigDict) -> None:
8080

8181
super(DeserializingConsumer, self).__init__(conf_copy)
8282

83-
def poll(self, timeout: float = -1) -> Optional['Message']:
83+
def poll(self, timeout: float = -1) -> Optional[Message]:
8484
"""
8585
Consume messages and calls callbacks.
8686

src/confluent_kafka/error.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class _KafkaClientError(KafkaException):
3535
by the broker.
3636
"""
3737

38-
def __init__(self, kafka_error: KafkaError, exception: Optional[Exception] = None, kafka_message: Optional[Message] = None) -> None:
38+
def __init__(self, kafka_error: KafkaError, exception: Optional[Exception] = None,
39+
kafka_message: Optional[Message] = None) -> None:
3940
super(_KafkaClientError, self).__init__(kafka_error)
4041
self.exception = exception
4142
self.kafka_message = kafka_message
@@ -67,7 +68,8 @@ class ConsumeError(_KafkaClientError):
6768
6869
"""
6970

70-
def __init__(self, kafka_error: KafkaError, exception: Optional[Exception] = None, kafka_message: Optional[Message] = None) -> None:
71+
def __init__(self, kafka_error: KafkaError, exception: Optional[Exception] = None,
72+
kafka_message: Optional[Message] = None) -> None:
7173
super(ConsumeError, self).__init__(kafka_error, exception, kafka_message)
7274

7375

src/confluent_kafka/serializing_producer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# limitations under the License.
1717
#
1818

19-
from typing import Any, Optional, Callable
19+
from typing import Any, Optional
2020

2121
from confluent_kafka.cimpl import Producer as _ProducerImpl
2222
from .serialization import (MessageField,

0 commit comments

Comments
 (0)