Skip to content

fix(client): Make the producer protocols' dest positional-only - #878

Merged
untitaker merged 1 commit into
mainfrom
chromy/2026-11-24-producer-dest-positional
Nov 25, 2026
Merged

untitaker merged 1 commit into
mainfrom
chromy/2026-11-24-producer-dest-positional

Conversation

@chromy

@chromy chromy commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ProducerProtocol.produce and CloseableProducerProtocol.produce name their first
parameter dest. arroyo's KafkaProducer.produce names it destination. Because
the protocol's parameter could be passed by keyword, a strict checker won't accept
a KafkaProducer as a ProducerProtocol. ty rejects Seer's producer factory:

error[invalid-argument-type]: Argument to `TaskbrokerApp.__init__` is incorrect
   --> src/seer/taskworker/app.py:135:5
    |
135 |     producer_factory=_producer_factory,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected `(str, /) -> ProducerProtocol`, found `def _producer_factory(topic: str) -> KafkaProducer`
info:         └── the parameter named `destination` does not match `dest` (and can be used as a keyword parameter)

mypy doesn't compare parameter names when matching protocols, so it allows this.
dest is now positional-only in both protocols. The registry already passes it
positionally.

`ProducerProtocol.produce` and `CloseableProducerProtocol.produce` name their first
parameter `dest`. arroyo's `KafkaProducer.produce` names it `destination`. Because
the protocol's parameter could be passed by keyword, a strict checker won't accept
a `KafkaProducer` as a `ProducerProtocol`. ty rejects Seer's producer factory:

```
error[invalid-argument-type]: Argument to `TaskbrokerApp.__init__` is incorrect
   --> src/seer/taskworker/app.py:135:5
    |
135 |     producer_factory=_producer_factory,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected `(str, /) -> ProducerProtocol`, found `def _producer_factory(topic: str) -> KafkaProducer`
info:         └── the parameter named `destination` does not match `dest` (and can be used as a keyword parameter)
```

mypy doesn't compare parameter names when matching protocols, so it allows this.
`dest` is now positional-only in both protocols. The registry already passes it
positionally. No behaviour changes.

I checked this by pointing Seer's ty at this branch's source: the error goes away.
mypy on the client reports the same errors before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chromy
chromy marked this pull request as ready for review November 24, 2026 18:07
@chromy
chromy requested a review from a team as a code owner November 24, 2026 18:07

@untitaker untitaker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh that's unfortunate. since protocols don't get their arg names checked, i wonder if we should make all protocols positional-only on principle. TIL

@untitaker
untitaker merged commit 1bd5a5f into main Nov 25, 2026
28 of 31 checks passed
@untitaker
untitaker deleted the chromy/2026-11-24-producer-dest-positional branch November 25, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants