Skip to content

Commit

Permalink
typing: Fix incorrect type annotations in on_message
Browse files Browse the repository at this point in the history
The type annotation for `on_message`’s `messages` argument has been incorrect,
and hasn’t matched the values that are being passed to it in tests.
`on_message` performs a conversion from the BlazingMQ wire protocol identifiers
for message property types, which are represented as `int`s, to the Python
SDK’s message property type enumeration, which are Python objects.  However,
the type annotation incorrectly documented that this conversion had already
taken place.  This patch updates the type annotation and makes the code that
does the conversion clearer.

Signed-off-by: Patrick M. Niedzielski <[email protected]>
  • Loading branch information
pniedzielski committed Dec 8, 2023
1 parent 145b260 commit 5353ba1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/blazingmq/_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def on_session_event(
user_callback(event)


PropertiesAndTypesDictsType = Tuple[
Dict[str, Union[int, bytes]], Dict[str, PropertyType]
]
PropertiesAndTypesDictsType = Tuple[Dict[str, Union[int, bytes]], Dict[str, int]]


def on_message(
Expand All @@ -115,10 +113,11 @@ def on_message(
assert ext_session is not None, "ext.Session has been deleted"
for data, guid, queue_uri, properties_tuple in messages:
properties, property_types = properties_tuple
for k, v in property_types.items():
property_types[k] = property_type_to_py[v]
property_types_py = {
k: property_type_to_py[v] for k, v in property_types.items()
}
message = create_message(
data, guid, queue_uri.decode(), properties, property_types
data, guid, queue_uri.decode(), properties, property_types_py
)
message_handle = create_message_handle(message, ext_session)
user_callback(message, message_handle)
Expand Down

0 comments on commit 5353ba1

Please sign in to comment.