Skip to content

Commit d03a695

Browse files
authored
Fix rebalance callback typing for ty 0.0.100 (#121)
Refs #120
1 parent 88342a1 commit d03a695

7 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎faststream_concurrent_aiokafka/middleware.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class KafkaConcurrentProcessingMiddleware(BaseMiddleware):
196196
# KafkaAckableMessage narrowing documents the MANUAL-ack design center; auto-ack/Fake paths
197197
# short-circuit before any narrowed access. Override widens to StreamMessage[Any] semantically
198198
# but ty flags the parameter narrowing as a Liskov violation.
199-
async def consume_scope( # ty: ignore[invalid-method-override]
199+
async def consume_scope( # ty: ignore[incompatible-method-override]
200200
self,
201201
call_next: typing.Callable[[KafkaAckableMessage], typing.Awaitable[typing.Any]],
202202
msg: KafkaAckableMessage,

‎faststream_concurrent_aiokafka/rebalance.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def from_context(
6767
def _resolve_committer(self) -> KafkaBatchCommitter | None:
6868
return self._committer
6969

70-
async def on_partitions_assigned(self, _assigned: object) -> None: # ty: ignore[invalid-method-override]
70+
async def on_partitions_assigned(self, assigned: object) -> None:
7171
pass
7272

7373
async def on_partitions_revoked(self, revoked: object) -> None:
@@ -97,7 +97,7 @@ def _resolve_committer(self) -> KafkaBatchCommitter | None:
9797
return None
9898
return handler.committer
9999

100-
async def on_partitions_assigned(self, assigned: object) -> None: # ty: ignore[invalid-method-override]
100+
async def on_partitions_assigned(self, assigned: object) -> None:
101101
if self._chained is not None:
102102
await _call_or_await(self._chained.on_partitions_assigned(assigned))
103103

‎tests/test_concurrent_processing.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ async def coro() -> str:
252252
await handler.handle_task(coro(), sample_record, sample_message) # ty: ignore[invalid-argument-type]
253253

254254
assert len(handler._tracked_tasks) == 1
255-
sent_commit_task: typing.Final = handler._committer.send_task.call_args[0][0] # ty: ignore[unresolved-attribute]
255+
sent_commit_task: typing.Final = handler._committer.send_task.call_args[0][0] # ty: ignore[missing-attribute]
256256
assert isinstance(sent_commit_task.asyncio_task, asyncio.Task)
257257
assert len(sent_commit_task.asyncio_task._callbacks) > 0
258258

@@ -275,7 +275,7 @@ async def coro() -> str:
275275

276276
await handler.handle_task(coro(), sample_record, sample_message) # ty: ignore[invalid-argument-type]
277277

278-
sent_commit_task: typing.Final = handler._committer.send_task.call_args[0][0] # ty: ignore[unresolved-attribute]
278+
sent_commit_task: typing.Final = handler._committer.send_task.call_args[0][0] # ty: ignore[missing-attribute]
279279
assert commit_structure_validate({sent_commit_task.topic_partition: 0})
280280

281281

@@ -299,14 +299,14 @@ async def coro() -> str:
299299
return "result"
300300

301301
await handler.handle_task(coro(), sample_record, sample_message) # ty: ignore[invalid-argument-type]
302-
handler._committer.send_task.assert_called_once() # ty: ignore[unresolved-attribute]
302+
handler._committer.send_task.assert_called_once() # ty: ignore[missing-attribute]
303303

304304

305305
async def test_concurrent_handles_committer_dead_error(
306306
handler: KafkaConcurrentHandler, sample_message: MockKafkaMessage, sample_record: MockConsumerRecord
307307
) -> None:
308308
await handler.start()
309-
handler._committer.send_task.side_effect = CommitterIsDeadError("Dead") # ty: ignore[unresolved-attribute]
309+
handler._committer.send_task.side_effect = CommitterIsDeadError("Dead") # ty: ignore[missing-attribute]
310310

311311
with pytest.raises(CommitterIsDeadError):
312312
await handler.handle_task(asyncio.sleep(0), sample_record, sample_message) # ty: ignore[invalid-argument-type]
@@ -322,7 +322,7 @@ async def test_concurrent_start_sets_running(handler: KafkaConcurrentHandler) ->
322322

323323
async def test_concurrent_start_creates_committer_when_enabled(handler: KafkaConcurrentHandler) -> None:
324324
await handler.start()
325-
handler._committer.spawn.assert_called_once() # ty: ignore[unresolved-attribute]
325+
handler._committer.spawn.assert_called_once() # ty: ignore[missing-attribute]
326326
assert handler.is_healthy
327327

328328

@@ -346,7 +346,7 @@ async def test_concurrent_stop_base(handler: KafkaConcurrentHandler) -> None:
346346
async def test_concurrent_stop_closes_committer(handler: KafkaConcurrentHandler) -> None:
347347
await handler.start()
348348
await handler.stop()
349-
handler._committer.close.assert_called_once() # ty: ignore[unresolved-attribute]
349+
handler._committer.close.assert_called_once() # ty: ignore[missing-attribute]
350350

351351

352352
async def test_concurrent_stop_when_not_running(

‎tests/test_kafka_committer.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,11 @@ async def done() -> None:
13551355
timeout=1.0,
13561356
) # never blocks
13571357

1358-
committer._commit_task.cancel() # ty: ignore[unresolved-attribute]
1358+
commit_task: typing.Final = committer._commit_task
1359+
assert commit_task is not None
1360+
commit_task.cancel()
13591361
with contextlib.suppress(asyncio.CancelledError):
1360-
await committer._commit_task # ty: ignore[invalid-await]
1362+
await commit_task
13611363

13621364

13631365
async def test_send_task_unblocks_with_dead_committer_error() -> None:
@@ -1399,9 +1401,11 @@ async def done() -> None:
13991401
await asyncio.sleep(0.05)
14001402
assert not blocked.done()
14011403

1402-
committer._commit_task.cancel() # ty: ignore[unresolved-attribute]
1404+
commit_task: typing.Final = committer._commit_task
1405+
assert commit_task is not None
1406+
commit_task.cancel()
14031407
with contextlib.suppress(asyncio.CancelledError):
1404-
await committer._commit_task # ty: ignore[invalid-await]
1408+
await commit_task
14051409

14061410
with pytest.raises(CommitterIsDeadError):
14071411
await asyncio.wait_for(blocked, timeout=1.0)

‎tests/test_middleware.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,10 +764,10 @@ async def handler(msg: typing.Any) -> None: ...
764764

765765
# No await: a coroutine-returning guard would merely warn here instead of raising.
766766
with pytest.raises(RuntimeError, match="ack"):
767-
guarded.ack() # ty: ignore[unresolved-attribute]
767+
guarded.ack() # ty: ignore[missing-attribute]
768768
# And it raises through an await too, since the call raises before the await happens.
769769
with pytest.raises(RuntimeError, match="ack"):
770-
await guarded.ack() # ty: ignore[unresolved-attribute]
770+
await guarded.ack() # ty: ignore[missing-attribute]
771771

772772

773773
async def test_middleware_does_not_guard_fake_consumer_passthrough(setup_broker: KafkaBroker) -> None:

‎tests/test_rebalance.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def test_rebalance_on_partitions_revoked_calls_commit_all(
3333
async def test_rebalance_on_partitions_assigned_is_noop(
3434
listener: ConsumerRebalanceListener, committer: MockKafkaBatchCommitter
3535
) -> None:
36-
await listener.on_partitions_assigned(set())
36+
await listener.on_partitions_assigned(assigned=set())
3737
committer.commit_all.assert_not_called()
3838

3939

‎tests/test_rebalance_attachment.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def test_a_user_listener_is_kept_and_still_called(*, is_async: bool) -> No
121121
try:
122122
handler.committer.commit_all = AsyncMock()
123123
await subscriber._listener.on_partitions_revoked(partitions)
124-
await subscriber._listener.on_partitions_assigned(partitions)
124+
await subscriber._listener.on_partitions_assigned(assigned=partitions)
125125
finally:
126126
await stop_concurrent_processing(broker.context)
127127

0 commit comments

Comments
 (0)