Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion faststream_concurrent_aiokafka/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class KafkaConcurrentProcessingMiddleware(BaseMiddleware):
# KafkaAckableMessage narrowing documents the MANUAL-ack design center; auto-ack/Fake paths
# short-circuit before any narrowed access. Override widens to StreamMessage[Any] semantically
# but ty flags the parameter narrowing as a Liskov violation.
async def consume_scope( # ty: ignore[invalid-method-override]
async def consume_scope( # ty: ignore[incompatible-method-override]
self,
call_next: typing.Callable[[KafkaAckableMessage], typing.Awaitable[typing.Any]],
msg: KafkaAckableMessage,
Expand Down
4 changes: 2 additions & 2 deletions faststream_concurrent_aiokafka/rebalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def from_context(
def _resolve_committer(self) -> KafkaBatchCommitter | None:
return self._committer

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

async def on_partitions_revoked(self, revoked: object) -> None:
Expand Down Expand Up @@ -97,7 +97,7 @@ def _resolve_committer(self) -> KafkaBatchCommitter | None:
return None
return handler.committer

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

Expand Down
12 changes: 6 additions & 6 deletions tests/test_concurrent_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async def coro() -> str:
await handler.handle_task(coro(), sample_record, sample_message) # ty: ignore[invalid-argument-type]

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

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

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

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


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

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


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

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

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


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


async def test_concurrent_stop_when_not_running(
Expand Down
12 changes: 8 additions & 4 deletions tests/test_kafka_committer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,11 @@ async def done() -> None:
timeout=1.0,
) # never blocks

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


async def test_send_task_unblocks_with_dead_committer_error() -> None:
Expand Down Expand Up @@ -1399,9 +1401,11 @@ async def done() -> None:
await asyncio.sleep(0.05)
assert not blocked.done()

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

with pytest.raises(CommitterIsDeadError):
await asyncio.wait_for(blocked, timeout=1.0)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,10 @@ async def handler(msg: typing.Any) -> None: ...

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


async def test_middleware_does_not_guard_fake_consumer_passthrough(setup_broker: KafkaBroker) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rebalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def test_rebalance_on_partitions_revoked_calls_commit_all(
async def test_rebalance_on_partitions_assigned_is_noop(
listener: ConsumerRebalanceListener, committer: MockKafkaBatchCommitter
) -> None:
await listener.on_partitions_assigned(set())
await listener.on_partitions_assigned(assigned=set())
committer.commit_all.assert_not_called()


Expand Down
2 changes: 1 addition & 1 deletion tests/test_rebalance_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def test_a_user_listener_is_kept_and_still_called(*, is_async: bool) -> No
try:
handler.committer.commit_all = AsyncMock()
await subscriber._listener.on_partitions_revoked(partitions)
await subscriber._listener.on_partitions_assigned(partitions)
await subscriber._listener.on_partitions_assigned(assigned=partitions)
finally:
await stop_concurrent_processing(broker.context)

Expand Down
Loading