Skip to content

Commit c650a77

Browse files
authored
Drop python2 support after kafka-python 2.3.x (#2699)
1 parent 9c20267 commit c650a77

File tree

165 files changed

+207
-3319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+207
-3319
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- "3.9.0"
3636
- "4.0.0"
3737
python:
38-
- "3.13"
38+
- "3.14"
3939
include:
4040
#- python: "pypy3.9"
4141
# kafka: "2.6.0"
@@ -50,6 +50,8 @@ jobs:
5050
kafka: "4.0.0"
5151
- python: "3.12"
5252
kafka: "4.0.0"
53+
- python: "3.13"
54+
kafka: "4.0.0"
5355

5456
steps:
5557
- uses: actions/checkout@v6

docs/compatibility.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Although kafka-python is tested and expected to work on recent broker versions,
1616
not all features are supported. Please see github open issues for feature tracking.
1717
PRs welcome!
1818

19-
kafka-python is tested on python 2.7, and 3.8-3.13.
19+
kafka-python is tested on python 3.8-3.14.
20+
python 2.7 was supported through kafka-python release 2.3.
2021

2122
Builds and tests via Github Actions Workflows. See https://github.com/dpkp/kafka-python/actions

kafka/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
__title__ = 'kafka'
42
from kafka.version import __version__
53
__author__ = 'Dana Powers'
@@ -8,14 +6,8 @@
86

97
# Set default logging handler to avoid "No handler found" warnings.
108
import logging
11-
try: # Python 2.7+
12-
from logging import NullHandler
13-
except ImportError:
14-
class NullHandler(logging.Handler):
15-
def emit(self, record):
16-
pass
179

18-
logging.getLogger(__name__).addHandler(NullHandler())
10+
logging.getLogger(__name__).addHandler(logging.NullHandler())
1911

2012

2113
from kafka.admin import KafkaAdminClient

kafka/admin/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from kafka.admin.config_resource import ConfigResource, ConfigResourceType
42
from kafka.admin.client import KafkaAdminClient
53
from kafka.admin.acl_resource import (ACL, ACLFilter, ResourcePattern, ResourcePatternFilter, ACLOperation,

kafka/admin/__main__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import sys
42

53
from kafka.cli.admin import run_cli

kafka/admin/acl_resource.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
from __future__ import absolute_import
2-
3-
# enum in stdlib as of py3.4
4-
try:
5-
from enum import IntEnum # pylint: disable=import-error
6-
except ImportError:
7-
# vendored backport module
8-
from kafka.vendor.enum34 import IntEnum
1+
from enum import IntEnum
92

103
from kafka.errors import IllegalArgumentError
114

kafka/admin/client.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division
2-
31
from collections import defaultdict
42
import copy
53
import itertools
@@ -8,7 +6,6 @@
86
import time
97

108
from . import ConfigResourceType
11-
from kafka.vendor import six
129

1310
from kafka.admin.acl_resource import ACLOperation, ACLPermissionType, ACLFilter, ACL, ResourcePattern, ResourceType, \
1411
ACLResourcePatternType, valid_acl_operations
@@ -122,8 +119,7 @@ class KafkaAdminClient(object):
122119
ssl_crlfile (str): Optional filename containing the CRL to check for
123120
certificate expiration. By default, no CRL check is done. When
124121
providing a file, only the leaf certificate will be checked against
125-
this CRL. The CRL can only be checked with Python 3.4+ or 2.7.9+.
126-
Default: None.
122+
this CRL. Default: None.
127123
api_version (tuple): Specify which Kafka API version to use. If set
128124
to None, KafkaClient will attempt to infer the broker version by
129125
probing various APIs. Example: (0, 10, 2). Default: None
@@ -420,11 +416,7 @@ def _send_request_to_controller(self, request):
420416
raise RuntimeError("This should never happen, please file a bug with full stacktrace if encountered")
421417

422418
def _parse_topic_request_response(self, topic_error_tuples, request, response, tries):
423-
# Also small py2/py3 compatibility -- py3 can ignore extra values
424-
# during unpack via: for x, y, *rest in list_of_values. py2 cannot.
425-
# So for now we have to map across the list and explicitly drop any
426-
# extra values (usually the error_message)
427-
for topic, error_code in map(lambda e: e[:2], topic_error_tuples):
419+
for topic, error_code, *_ in topic_error_tuples:
428420
error_type = Errors.for_code(error_code)
429421
if tries and error_type is Errors.NotControllerError:
430422
# No need to inspect the rest of the errors for
@@ -439,12 +431,8 @@ def _parse_topic_request_response(self, topic_error_tuples, request, response, t
439431
return True
440432

441433
def _parse_topic_partition_request_response(self, request, response, tries):
442-
# Also small py2/py3 compatibility -- py3 can ignore extra values
443-
# during unpack via: for x, y, *rest in list_of_values. py2 cannot.
444-
# So for now we have to map across the list and explicitly drop any
445-
# extra values (usually the error_message)
446434
for topic, partition_results in response.replication_election_results:
447-
for partition_id, error_code in map(lambda e: e[:2], partition_results):
435+
for partition_id, error_code, *_ in partition_results:
448436
error_type = Errors.for_code(error_code)
449437
if tries and error_type is Errors.NotControllerError:
450438
# No need to inspect the rest of the errors for
@@ -1418,7 +1406,7 @@ def _list_consumer_group_offsets_request(self, group_id, partitions=None):
14181406
topics_partitions_dict = defaultdict(set)
14191407
for topic, partition in partitions:
14201408
topics_partitions_dict[topic].add(partition)
1421-
topics_partitions = list(six.iteritems(topics_partitions_dict))
1409+
topics_partitions = list(topics_partitions_dict.items())
14221410
return OffsetFetchRequest[version](group_id, topics_partitions)
14231411

14241412
def _list_consumer_group_offsets_process_response(self, response):

kafka/admin/config_resource.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
from __future__ import absolute_import
2-
3-
# enum in stdlib as of py3.4
4-
try:
5-
from enum import IntEnum # pylint: disable=import-error
6-
except ImportError:
7-
# vendored backport module
8-
from kafka.vendor.enum34 import IntEnum
1+
from enum import IntEnum
92

103

114
class ConfigResourceType(IntEnum):

kafka/admin/new_partitions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import
2-
3-
41
class NewPartitions(object):
52
"""A class for new partition creation on existing topics. Note that the length of new_assignments, if specified,
63
must be the difference between the new total number of partitions and the existing number of partitions.

kafka/admin/new_topic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import
2-
3-
41
class NewTopic(object):
52
""" A class for new topic creation
63
Arguments:

0 commit comments

Comments
 (0)