Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cee4d17

Browse files
committed
Update docs for api_version_auto_timeout_ms (dpkp#1812)
The docs for `api_version_auto_timeout_ms` mention setting `api_version='auto'` but that value has been deprecated for years in favor of `api_version=None`. Updating the docs for now, and will remove support for `'auto'` in next major version bump.
1 parent 1a0f297 commit cee4d17

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

kafka/consumer/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class KafkaConsumer(six.Iterator):
209209
Default: None
210210
api_version_auto_timeout_ms (int): number of milliseconds to throw a
211211
timeout exception from the constructor when checking the broker
212-
api version. Only applies if api_version set to 'auto'
212+
api version. Only applies if api_version set to None.
213213
connections_max_idle_ms: Close idle connections after the number of
214214
milliseconds specified by this config. The broker closes idle
215215
connections after connections.max.idle.ms, so this avoids hitting

kafka/producer/kafka.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class KafkaProducer(object):
255255
various APIs. Example: (0, 10, 2). Default: None
256256
api_version_auto_timeout_ms (int): number of milliseconds to throw a
257257
timeout exception from the constructor when checking the broker
258-
api version. Only applies if api_version set to 'auto'
258+
api version. Only applies if api_version set to None.
259259
metric_reporters (list): A list of classes to use as metrics reporters.
260260
Implementing the AbstractMetricsReporter interface allows plugging
261261
in classes that will be notified of new metric creation. Default: []

test/fixtures.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
def random_string(length):
2727
return "".join(random.choice(string.ascii_letters) for i in range(length))
2828

29-
def version_str_to_list(version_str):
30-
return tuple(map(int, version_str.split('.'))) # e.g., (0, 8, 1, 1)
29+
def version_str_to_tuple(version_str):
30+
"""Transform a version string into a tuple.
31+
32+
Example: '0.8.1.1' --> (0, 8, 1, 1)
33+
"""
34+
return tuple(map(int, version_str.split('.')))
3135

3236
def version():
3337
if 'KAFKA_VERSION' not in os.environ:
3438
return ()
35-
return version_str_to_list(os.environ['KAFKA_VERSION'])
39+
return version_str_to_tuple(os.environ['KAFKA_VERSION'])
3640

3741
def get_open_port():
3842
sock = socket.socket()

test/testutil.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@
1616
FailedPayloadsError
1717
)
1818
from kafka.structs import OffsetRequestPayload
19-
from test.fixtures import random_string, version_str_to_list, version as kafka_version #pylint: disable=wrong-import-order
19+
from test.fixtures import random_string, version_str_to_tuple, version as kafka_version #pylint: disable=wrong-import-order
2020

2121

2222
def kafka_versions(*versions):
23+
"""
24+
Describe the Kafka versions this test is relevant to.
25+
26+
The versions are passed in as strings, for example:
27+
'0.11.0'
28+
'>=0.10.1.0'
29+
'>0.9', '<1.0' # since this accepts multiple versions args
30+
31+
The current KAFKA_VERSION will be evaluated against this version. If the
32+
result is False, then the test is skipped. Similarly, if KAFKA_VERSION is
33+
not set the test is skipped.
34+
35+
Note: For simplicity, this decorator accepts Kafka versions as strings even
36+
though the similarly functioning `api_version` only accepts tuples. Trying
37+
to convert it to tuples quickly gets ugly due to mixing operator strings
38+
alongside version tuples. While doable when one version is passed in, it
39+
isn't pretty when multiple versions are passed in.
40+
"""
2341

2442
def construct_lambda(s):
2543
if s[0].isdigit():
@@ -43,7 +61,7 @@ def construct_lambda(s):
4361
'<=': operator.le
4462
}
4563
op = op_map[op_str]
46-
version = version_str_to_list(v_str)
64+
version = version_str_to_tuple(v_str)
4765
return lambda a: op(a, version)
4866

4967
validators = map(construct_lambda, versions)

0 commit comments

Comments
 (0)