Skip to content

Commit 94edfe2

Browse files
committed
A little python cleanup
1. Remove unused variable: `partitions_for_topic` 2. No need to cast to list as `sorted()` already returns a list 3. Using enumerate is cleaner than `range(len())` and handles assigning `member`
1 parent f6a8a38 commit 94edfe2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kafka/coordinator/assignors/range.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,18 @@ def assign(cls, cluster, member_metadata):
4646
if partitions is None:
4747
log.warning('No partition metadata for topic %s', topic)
4848
continue
49-
partitions = sorted(list(partitions))
50-
partitions_for_topic = len(partitions)
49+
partitions = sorted(partitions)
5150
consumers_for_topic.sort()
5251

5352
partitions_per_consumer = len(partitions) // len(consumers_for_topic)
5453
consumers_with_extra = len(partitions) % len(consumers_for_topic)
5554

56-
for i in range(len(consumers_for_topic)):
55+
for i, member in enumerate(consumers_for_topic):
5756
start = partitions_per_consumer * i
5857
start += min(i, consumers_with_extra)
5958
length = partitions_per_consumer
6059
if not i + 1 > consumers_with_extra:
6160
length += 1
62-
member = consumers_for_topic[i]
6361
assignment[member][topic] = partitions[start:start+length]
6462

6563
protocol_assignment = {}

0 commit comments

Comments
 (0)