[EventHub] Fix mypy errors in _common, _transport, and _utils#46988
Open
j7nw4r wants to merge 3 commits into
Open
[EventHub] Fix mypy errors in _common, _transport, and _utils#46988j7nw4r wants to merge 3 commits into
j7nw4r wants to merge 3 commits into
Conversation
Resolves 16 mypy errors that surface in CI (e.g., PR #46953) without changing runtime behavior: - _common.py: widen message_id/content_type/correlation_id setters to Optional[str] so EventData.__init__ can clear them, narrow Optional accesses on annotations/application_properties, and silence one residual update() arg-type with a typed ignore. - _transport/_base.py, aio/_transport/_base_async.py: keep_alive_interval is Optional[int] (None means 'no keep-alive') and create_source.offset is Optional[Union[int, str, datetime.datetime]] (matches event_position). - _transport/_pyamqp_transport.py, _uamqp_transport.py, and async equivalents: align keep_alive_interval signatures with the new abstract type to satisfy Liskov. - _utils.event_position_selector: accept Optional value (already handled at runtime via the else branch). No source files imported by user-facing API surfaces change behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Event Hubs type annotations and small narrowing patterns to address existing mypy failures in common message handling and AMQP transport abstractions.
Changes:
- Widens producer keep-alive transport signatures to accept
Optional[int]. - Updates source/selector offset typing to allow optional string/int/datetime event positions.
- Adds
Nonehandling for AMQP annotations/properties access inEventData.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
sdk/eventhub/azure-eventhub/azure/eventhub/_common.py |
Narrows optional AMQP annotations/properties and updates message property setters. |
sdk/eventhub/azure-eventhub/azure/eventhub/_utils.py |
Allows optional event positions in selector helper typing. |
sdk/eventhub/azure-eventhub/azure/eventhub/_transport/_base.py |
Updates sync transport abstract method annotations. |
sdk/eventhub/azure-eventhub/azure/eventhub/_transport/_pyamqp_transport.py |
Aligns pyamqp send client keep-alive typing. |
sdk/eventhub/azure-eventhub/azure/eventhub/_transport/_uamqp_transport.py |
Aligns uamqp send client keep-alive typing. |
sdk/eventhub/azure-eventhub/azure/eventhub/aio/_transport/_base_async.py |
Updates async transport abstract method annotations. |
sdk/eventhub/azure-eventhub/azure/eventhub/aio/_transport/_pyamqp_transport_async.py |
Aligns async pyamqp send client keep-alive typing. |
sdk/eventhub/azure-eventhub/azure/eventhub/aio/_transport/_uamqp_transport_async.py |
Aligns async uamqp send client keep-alive typing. |
| :rtype: dict[str, any] or dict[bytes, any] | ||
| """ | ||
| return self._raw_amqp_message.application_properties | ||
| return self._raw_amqp_message.application_properties or {} |
Member
Author
There was a problem hiding this comment.
Fixed in a93abe7 — the getter now lazily initializes application_properties = {} on the raw AMQP message when None, then returns it, so in-place mutations like event.properties["key"] = value persist on the backing message.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes #46986
What
Resolve the 16 mypy errors in
azure-eventhubthat fail the Build Analyze stage. Surfaced in PR #46953 CI but pre-existing onmain.Errors fixed
How
_common.py: widenmessage_id/content_type/correlation_idsetters toOptional[str]so the__init__clears work; narrowOptionalaccesses onannotations/application_propertieswithor {}patterns or explicitNonechecks; one residualupdate()mismatch silenced with a targeted# type: ignore[arg-type]._transport/_base.py+aio/_transport/_base_async.py:keep_alive_intervalisOptional[int](Noneis documented as "no keep-alive");create_source.offsetisOptional[Union[int, str, datetime.datetime]]to matchevent_position._pyamqp_transport,_uamqp_transport, and async variants): alignkeep_alive_intervalsignatures with the new abstract type so Liskov holds._utils.event_position_selector: acceptOptionalvalue (already handled at runtime by the else branch).No runtime behavior change. Verified with
mypy 1.19.1(the version CI uses):Success: no issues found in 99 source fileson src and43 source fileson samples.