Wrap awscrt types out of public MQTT signatures (#101)#105
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes awscrt SDK types from the library’s public/semi-public MQTT-facing type hints by introducing library-owned MQTT transport types (QoS, MqttConnectionHandle) and translating to/from awscrt only at connection-layer call sites. It also prevents AwsCrtError from leaking out of NavienMqttClient.publish() by wrapping unexpected CRT publish errors in MqttPublishError, keeping awscrt as an internal implementation detail.
Changes:
- Added
nwp500.mqtt.typeswith a library-ownedQoSIntEnum, aMqttConnectionHandlealias, and QoS translation helpers. - Updated MQTT client/connection/subscription/queue/public exports (and tests) to use
QoSinstead ofawscrt.mqtt.QoS, translating only at the boundary. - Wrapped otherwise-uncaught
AwsCrtErrorinNavienMqttClient.publish()asMqttPublishErrorto prevent SDK exceptions from escaping the public API.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/nwp500/mqtt/types.py |
Introduces library-owned MQTT types (QoS, MqttConnectionHandle) and translation functions as the boundary to awscrt. |
src/nwp500/mqtt/connection.py |
Replaces awscrt QoS/Connection type hints with library types and translates QoS at publish/subscribe call sites. |
src/nwp500/mqtt/subscriptions.py |
Stores/accepts library QoS for subscriptions and translates QoS when calling the underlying connection. |
src/nwp500/mqtt/client.py |
Updates public MQTT method signatures to QoS and wraps unexpected AwsCrtError in MqttPublishError at the public boundary. |
src/nwp500/mqtt/command_queue.py |
Updates queued command enqueue signature to accept library QoS. |
src/nwp500/mqtt/utils.py |
Updates QueuedCommand.qos type annotation to library QoS. |
src/nwp500/mqtt/__init__.py |
Re-exports QoS from nwp500.mqtt. |
src/nwp500/__init__.py |
Re-exports QoS at top-level nwp500.QoS. |
tests/test_protocol_correctness.py |
Updates tests to use library QoS instead of awscrt.mqtt.QoS. |
tests/test_mqtt_reliability.py |
Updates tests to use library QoS for subscribe calls. |
tests/test_command_queue.py |
Updates tests to use library QoS in QueuedCommand construction. |
CHANGELOG.rst |
Documents the public API change and the migration from awscrt.mqtt.QoS to nwp500.QoS. |
Introduce a library-owned QoS IntEnum and MqttConnectionHandle alias in nwp500/mqtt/types.py, translating to/from awscrt.mqtt.QoS only at the connection-layer boundary. Replace awscrt.mqtt.QoS and awscrt.mqtt.Connection type references across NavienMqttClient, MqttConnection, MqttSubscriptionManager, MqttCommandQueue and QueuedCommand. Wrap otherwise uncaught AwsCrtError in MqttPublishError at the public publish() boundary so awscrt exceptions no longer leak. Export QoS from nwp500 and nwp500.mqtt. Update tests to use the library QoS enum.
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.
Summary
Removes awscrt SDK types from the library's public/semi-public MQTT signatures so awscrt stays an internal implementation detail.
Changes
src/nwp500/mqtt/types.pydefining:QoS(IntEnum, values match the MQTT wire protocol /awscrt.mqtt.QoS)MqttConnectionHandlealias for the internal connection objectto_awscrt_qos/from_awscrt_qostranslators — the single boundary that touchesawscrt.mqtt.QoSQoSnow replacesawscrt.mqtt.QoSonpublish/subscribeofNavienMqttClient,MqttConnection,MqttSubscriptionManager, onMqttCommandQueue.enqueue, and theQueuedCommanddataclass. Translation to/from awscrt happens only at the connection-layer call sites.awscrt.mqtt.Connectionhandles are typed behindMqttConnectionHandle; connection-interrupted callback error params are typedException(matching the existingConnectionInterruptedEvent.errortype).NavienMqttClient.publishwraps otherwise-uncaughtAwsCrtErrorinMqttPublishErrorso awscrt exceptions no longer propagate out of the public boundary.QoSexported fromnwp500andnwp500.mqtt.QoSenum.No awscrt types appear in public/exported signatures, behavior is unchanged, and awscrt remains internal.
Validation
scripts/lint.py(ruff + pyright): passedmypy src/nwp500: no issues in 50 filespytest: 611 passedCloses #101