Skip to content

Commit 3e5b214

Browse files
committed
header_class() abstractmethod to avoid the insanity
1 parent 964bcc4 commit 3e5b214

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

kafka/protocol/api.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ def encode(self, header=False, framed=False):
7474
return b''.join(bits)
7575

7676
@classmethod
77-
@abc.abstractproperty
77+
@abc.abstractmethod
7878
def header_class(cls):
7979
pass
8080

8181
@classmethod
8282
def parse_header(cls, read_buffer):
83-
klass = cls.header_class
84-
return klass.decode(read_buffer)
83+
return cls.header_class().decode(read_buffer)
8584

8685
@classmethod
8786
def decode(cls, data, header=False, framed=False):
@@ -109,14 +108,12 @@ def expect_response(self):
109108
return True
110109

111110
def with_header(self, correlation_id=0, client_id='kafka-python'):
112-
klass = self.header_class
113111
if self.FLEXIBLE_VERSION:
114-
self._header = klass(self.API_KEY, self.API_VERSION, correlation_id, client_id, {})
112+
self._header = self.header_class()(self.API_KEY, self.API_VERSION, correlation_id, client_id, {})
115113
else:
116-
self._header = klass(self.API_KEY, self.API_VERSION, correlation_id, client_id)
114+
self._header = self.header_class()(self.API_KEY, self.API_VERSION, correlation_id, client_id)
117115

118116
@classmethod
119-
@property
120117
def header_class(cls):
121118
if cls.FLEXIBLE_VERSION:
122119
return RequestHeaderV2
@@ -131,14 +128,12 @@ def encode(self, header=False, framed=False, correlation_id=None, client_id=None
131128

132129
class Response(RequestResponse):
133130
def with_header(self, correlation_id=0):
134-
klass = self.header_class
135131
if self.FLEXIBLE_VERSION:
136-
self._header = klass(correlation_id, {})
132+
self._header = self.header_class()(correlation_id, {})
137133
else:
138-
self._header = klass(correlation_id)
134+
self._header = self.header_class()(correlation_id)
139135

140136
@classmethod
141-
@property
142137
def header_class(cls):
143138
if cls.FLEXIBLE_VERSION:
144139
return ResponseHeaderV2

0 commit comments

Comments
 (0)