Skip to content

fix(mqtt): subscriber() is typed by max_workers, so a decorated handler stays typed - #3123

Merged
borisalekseev merged 1 commit into
mainfrom
fix/mqtt-subscriber-overloads
Sep 12, 2026
Merged

borisalekseev merged 1 commit into
mainfrom
fix/mqtt-subscriber-overloads

Conversation

@Lancetnik

Copy link
Copy Markdown
Member

Description

MQTTRegistrator.subscriber returns MQTTDefaultSubscriber | MQTTConcurrentSubscriber. Strict mypy treats a union-typed decorator as untyped, so any handler under @broker.subscriber(...) on an MQTTBroker or MQTTRouter reports untyped-decorator, and the handler loses its type:

@broker.subscriber("t")
def handle() -> None: ...
# error: Untyped decorator makes function "handle" untyped  [untyped-decorator]

The registrator gains the two max_workers overloads the MQTT FastAPI router already has: max_workers: Literal[1] returns MQTTDefaultSubscriber, any other int returns MQTTConcurrentSubscriber. tests/mypy/mqtt.py pins both subscriber types and the decorated handler's type; both checks go red on the old registrator.

Split out of #3120, where the MQTT Call assertions needed it; it is a fix on its own.

Type of change

  • Bug fix (a non-breaking change that resolves an issue)

Checklist

  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • I have ensured that static analysis tests are passing by running just static-analysis

🤖 Generated with Claude Code

…andler stays typed

`MQTTRegistrator.subscriber` returned `MQTTDefaultSubscriber |
MQTTConcurrentSubscriber`, and strict mypy counts a union-typed decorator
as untyped: every `@broker.subscriber(...)` on an MQTT broker or router
reported `untyped-decorator`. The two `max_workers` overloads the MQTT
FastAPI router already has now sit on the registrator too, so the
subscriber and the decorated handler get their exact types.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@borisalekseev
borisalekseev added this pull request to the merge queue Sep 12, 2026
Merged via the queue into main with commit 10080a6 Sep 12, 2026
33 checks passed
@borisalekseev
borisalekseev deleted the fix/mqtt-subscriber-overloads branch September 12, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MQTT Issues related to `faststream.mqtt` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants