Repository navigation
fix(redis): stop ListBatchPublisher from passing as a ListPublisher - #3242
Merged
IvanKirpichnikov merged 2 commits intoSep 29, 2026
Merged
Conversation
ListBatchPublisher subclassed ListPublisher while replacing
`publish(message, list, ...)` with `publish(*messages, list=...)`. Code
typed against ListPublisher, including the `ListPublisher |
ListBatchPublisher` union that `publisher(list=ListSub(q, batch=flag))`
returns, type checked `pub.publish("hello", "other")`. On a batch
publisher that call sends ["hello", "other"] as one batch to the
publisher's own list.
The shared part (constructor, `list`, `subscriber_property`, `request`)
moves to `_ListPublisherMixin`, and both publishers derive from it, the
way `_ListHandlerMixin` already splits the list subscribers. No method
changes; `isinstance(batch_publisher, ListPublisher)` is now False.
pyrefly reported it as bad-override on `ListBatchPublisher.publish`, the
one override among its findings that a user can hit (ag2ai#3202).
vyhuholl
requested review from
IvanKirpichnikov and
powersemmi
as code owners
September 26, 2026 02:01
7 tasks
Moving `request()` into `_ListPublisherMixin` counts its lines as changed, and diff-cover found no test that ever calls it: the shared request testcase only builds a channel publisher for redis. The new case runs in memory and against a real Redis.
IvanKirpichnikov
requested changes
Sep 28, 2026
IvanKirpichnikov
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part of #3202.
ListBatchPublishersubclassedListPublisherbut replacedpublish(message, list, reply_to, ...)withpublish(*messages, list=..., ...). mypy accepts that override, since every positional argument still fits*messages, but the meaning changes. Code written againstListPublishertype checks a call that silently does something else on a batch publisher:It also applies without an explicit annotation:
publisher(list=ListSub(q, batch=flag))returnsListPublisher | ListBatchPublisher, and the same call type checks on that union. The snippet above behaves this way underTestRedisBroker.Among pyrefly's 104
bad-override*findings onfaststream/, this one (redis/publisher/usecase.py:263) is the only override a user can hit. The rest are summarized in #3202.Fix
What the two publishers share (the constructor,
list,subscriber_property,request) moves to_ListPublisherMixin, andListPublisherandListBatchPublisherboth derive from it. The list subscribers are already split this way through_ListHandlerMixin, and Kafka'sDefaultPublisher/BatchPublisherare siblings too. No method changes.What changes for users:
isinstance(batch_publisher, ListPublisher)is nowFalse, and passing aListBatchPublisherwhereListPublisheris annotated is a type error. Nothing infaststream/,tests/,docs/docs_src/orexamples/relies on either.Tests
tests/mypy/redis.pypasses a batch publisher to a function annotated withListPublisher, under# type: ignore[arg-type]. On the old hierarchy mypy fails it withunused-ignore. Runtime behaviour isn't changed, so there's no runtime test.Type of change
Please delete options that are not relevant.
Checklist
just lintshows no errors)just test-coveragejust static-analysis