Skip to content

[EventHub] Fix mypy errors in _common, _transport, and _utils#46988

Open
j7nw4r wants to merge 3 commits into
mainfrom
fix/eventhub-mypy-typing
Open

[EventHub] Fix mypy errors in _common, _transport, and _utils#46988
j7nw4r wants to merge 3 commits into
mainfrom
fix/eventhub-mypy-typing

Conversation

@j7nw4r
Copy link
Copy Markdown
Member

@j7nw4r j7nw4r commented May 19, 2026

Fixes #46986

What

Resolve the 16 mypy errors in azure-eventhub that fail the Build Analyze stage. Surfaced in PR #46953 CI but pre-existing on main.

Errors fixed

azure/eventhub/_common.py:142,143,144     Incompatible types in assignment (None vs str)
azure/eventhub/_common.py:321,330,340,351 Item "None" of "dict[..] | None" has no attribute "get"
azure/eventhub/_common.py:359             Incompatible return value type (Optional[Dict] vs Dict)
azure/eventhub/_common.py:405             update() got dict[str|bytes, Any] | None
azure/eventhub/_common.py:489,509,531     Item "None" of "AmqpMessageProperties | None" has no attribute "*"
azure/eventhub/_producer.py:135           keep_alive_interval: expected int, got Any | None
azure/eventhub/_consumer.py:132,133       create_source/event_position_selector: expected int, got Any | None
azure/eventhub/aio/_consumer_async.py:135 event_position_selector: expected int, got Any | None

How

  • _common.py: widen message_id / content_type / correlation_id setters to Optional[str] so the __init__ clears work; narrow Optional accesses on annotations / application_properties with or {} patterns or explicit None checks; one residual update() mismatch silenced with a targeted # type: ignore[arg-type].
  • _transport/_base.py + aio/_transport/_base_async.py: keep_alive_interval is Optional[int] (None is documented as "no keep-alive"); create_source.offset is Optional[Union[int, str, datetime.datetime]] to match event_position.
  • Concrete transports (_pyamqp_transport, _uamqp_transport, and async variants): align keep_alive_interval signatures with the new abstract type so Liskov holds.
  • _utils.event_position_selector: accept Optional value (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 files on src and 43 source files on samples.

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>
@j7nw4r j7nw4r marked this pull request as ready for review May 19, 2026 15:15
@j7nw4r j7nw4r requested a review from axisc as a code owner May 19, 2026 15:15
Copilot AI review requested due to automatic review settings May 19, 2026 15:15
@j7nw4r j7nw4r requested review from hmlam and sjkwak as code owners May 19, 2026 15:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 None handling for AMQP annotations/properties access in EventData.

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 {}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Johnathan Walker and others added 2 commits May 19, 2026 10:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azure-eventhub: mypy reports 16 type errors on main (Build Analyze fails)

2 participants