Repository navigation
fix(typing): accept every broker where BrokerUsecase[Any, Any] is annotated - #3222
Merged
Merged
Conversation
…otated Since 0.7.6 each broker binds the third parameter of BrokerUsecase to its own config class. The parameter was invariant with a BrokerConfig default, so `BrokerUsecase[Any, Any]` meant `BrokerUsecase[Any, Any, BrokerConfig]` and rejected every concrete broker: dishka's `setup_dishka(broker=...)` failed mypy with arg-type for all of them. Make the TypeVar covariant, rename it to BrokerConfigType_co as PLC0105 asks, and pin the behaviour in tests/mypy, which mypy, pyright and pyrefly all read. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…s it to the PR Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e commits it to the PR" This reverts commit 272b0c2.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
IvanKirpichnikov
requested changes
Sep 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IvanKirpichnikov
approved these changes
Sep 23, 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
Since 0.7.6 an integration annotated with
BrokerUsecase[Any, Any]rejects every concrete broker. dishka'ssetup_dishka(broker=...)is the reported case:#3029 made each broker bind the third parameter of
BrokerUsecaseto its own config (BrokerUsecase[IncomingMessage, RobustConnection, RabbitBrokerConfig]). That parameter was an invariant TypeVar withdefault=BrokerConfig, soBrokerUsecase[Any, Any]expands toBrokerUsecase[Any, Any, BrokerConfig], and no subclass config matches it. Before 0.7.6 every broker left the parameter at its default, so the types happened to line up.What changes
BrokerConfigTypebecomes covariant and is renamed toBrokerConfigType_co, as ruff's PLC0105 requires and as the other covariant TypeVars in the repo are named. It lives infaststream._internal, so the rename is not public API.tests/mypy/broker.pypasses all six brokers to functions annotated withBrokerUsecase[Any, Any]andBrokerUsecase[Any, Any, Any].tests/mypyis read by mypy, pyright and pyrefly, so the behaviour is pinned under all three.Checked
arg-typeerrors, one per broker. With it, it passes.just mypy(1850 files),just pyright,just pyrefly,just linter,just import-linterandjust slotscheckare clean.Trade-off
self.configis mutable, so covariance is not strictly sound. Neither checker flags it, and it restores what every third-party wrapper relied on until 0.7.5.Type of change