Skip to content

chore: three small clean-ups in one PR - #3100

Merged
borisalekseev merged 2 commits into
mainfrom
chore/prefactor-small-chores
Sep 7, 2026
Merged

chore: three small clean-ups in one PR#3100
borisalekseev merged 2 commits into
mainfrom
chore/prefactor-small-chores

Conversation

@Lancetnik

Copy link
Copy Markdown
Member

Description

Two clean-ups too small to review on their own, extracted from #3030 so the feature branch stops carrying them:

  • PATH_CONTEXT_PREFIX — the context prefix a Path() parameter reads from ("message.path.") has exactly one definition, in faststream/_internal/constants.py, and Path() reads it from there. It was spelled inline before.
  • parser_for(version) in faststream/mqtt/parser.py — the MQTT Subscriber and the in-memory MQTT test broker choose the parser class for a Broker version through this one function. Each picked it on its own before, and the two have to agree on which version they speak.

The third item the ticket lists, the .gitignore entries for local agent tooling and the graphify output, is already on main, so it is not part of this PR.

Nothing a user can see changes. No new tests: the change is one definition replacing two identical ones, and the existing MQTT and Path() suites pin the behaviour.

Part of the prefactor plan for #2451.

Type of change

  • Refactor (no functional change)

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
  • Existing tests pass: tests/utils/context/test_path.py, tests/brokers/mqtt/test_path.py, tests/brokers/mqtt/test_testclient.py, tests/docs/mqtt/message/test_message.py (-m "not connected"; MQTT connected tests run in CI only)
  • just mypy passes

🤖 Generated with Claude Code

The context prefix a `Path()` parameter reads from has one definition,
`PATH_CONTEXT_PREFIX`, instead of a string spelled inline. The MQTT
Subscriber and the in-memory MQTT test broker choose the parser class
for a Broker version through one function, `parser_for`, instead of
each deciding on its own.

Nothing a user can see changes. Prefactor extracted from #3030.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the MQTT Issues related to `faststream.mqtt` module label Sep 7, 2026

@borisalekseev borisalekseev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Better to narrow the mqtt version string type to Literal["3.1.1", "5.0"] and use typing.assert_never. This will simplify the work when adding a protocol version, and mypy will highlight places where corrections need to be made.

…re exhaustive

`MQTTVersion = Literal["3.1.1", "5.0"]` is spelled once, in the parser
module, and the Broker, the FastAPI router, the Broker config and the
test broker read their version through it. `parser_for` and the
producer choice in the Broker constructor switch over it exhaustively
with `assert_never`, so adding a protocol version is an edit to the
alias and mypy names every switch that has to learn it.

The Subscriber reads its version as the config spells it, `MQTTVersion`
or "unset", and resolves "unset" to 5.0 where it is known why: a
Subscriber declared on a Router reads before a Broker composes its
version in.

Requested in review by @borisalekseev.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Lancetnik

Copy link
Copy Markdown
Member Author

Done in the second commit.

  • MQTTVersion = Literal["3.1.1", "5.0"] lives once, in faststream/mqtt/parser.py, and MQTTBroker, MQTTRouter (FastAPI), MQTTBrokerConfig and the test broker spell their version through it.
  • parser_for and the producer choice in MQTTBroker.__init__ switch over it with typing_extensions.assert_never (the project supports 3.10, so not typing.assert_never). Adding a version is now an edit to the alias, and mypy names both switches.
  • The one place a third value exists is the config: version: MQTTVersion | Literal["unset"], "unset" being a Subscriber declared on a Router before a Broker composes its version in. The Subscriber resolves that to 5.0 explicitly, where the comment already explained it, instead of the previous getattr(..., "5.0") swallowing it.

just mypy and just pyright are clean; the MQTT test files pass locally without connected.

@borisalekseev
borisalekseev added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit d180d3e Sep 7, 2026
30 checks passed
@borisalekseev
borisalekseev deleted the chore/prefactor-small-chores branch September 7, 2026 21:38
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.

3 participants