Skip to content

Commit a7d5d80

Browse files
committed
Moved defaults to the class attribute.
1 parent 19e1393 commit a7d5d80

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

kafka/consumer/group.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class KafkaConsumer(six.Iterator):
166166
"""
167167
DEFAULT_CONFIG = {
168168
'bootstrap_servers': 'localhost',
169+
'client': None,
169170
'client_id': 'kafka-python-' + __version__,
170171
'group_id': 'kafka-python-default-group',
171172
'key_deserializer': None,
@@ -204,8 +205,6 @@ class KafkaConsumer(six.Iterator):
204205
}
205206

206207
def __init__(self, *topics, **configs):
207-
client = configs.pop("client", None)
208-
209208
self.config = copy.copy(self.DEFAULT_CONFIG)
210209
for key in self.config:
211210
if key in configs:
@@ -231,9 +230,7 @@ def __init__(self, *topics, **configs):
231230
metric_group_prefix = 'consumer'
232231
# TODO _metrics likely needs to be passed to KafkaClient, etc.
233232

234-
if client is None:
235-
client = KafkaClient(**self.config)
236-
self._client = client
233+
self._client = self.config['client'] or KafkaClient(**self.config)
237234

238235
# Check Broker Version if not set explicitly
239236
if self.config['api_version'] == 'auto':

kafka/producer/kafka.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class KafkaProducer(object):
226226
"""
227227
_DEFAULT_CONFIG = {
228228
'bootstrap_servers': 'localhost',
229+
'client': None,
229230
'client_id': None,
230231
'key_serializer': None,
231232
'value_serializer': None,
@@ -256,7 +257,7 @@ class KafkaProducer(object):
256257
'api_version': 'auto',
257258
}
258259

259-
def __init__(self, client=None, **configs):
260+
def __init__(self, **configs):
260261
log.debug("Starting the Kafka producer") # trace
261262
self.config = copy.copy(self._DEFAULT_CONFIG)
262263
for key in self.config:
@@ -273,9 +274,7 @@ def __init__(self, client=None, **configs):
273274
if self.config['acks'] == 'all':
274275
self.config['acks'] = -1
275276

276-
if client is None:
277-
client = KafkaClient(**self.config)
278-
self.client = client
277+
self.client = self.config['client'] or KafkaClient(**self.config)
279278

280279
# Check Broker Version if not set explicitly
281280
if self.config['api_version'] == 'auto':

0 commit comments

Comments
 (0)