Skip to content

Commit 5fe6662

Browse files
acrocagithub-actions[bot]
authored andcommitted
feat: Add aio module and update mypy configuration to include aio files (#942)
Signed-off-by: Albert Callarisa <albert@diagrid.io> (cherry picked from commit 8589d2e)
1 parent 5dec36a commit 5fe6662

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

dapr/aio/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Copyright 2026 The Dapr Authors
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""

dapr/aio/clients/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def invoke_method(
103103
self,
104104
app_id: str,
105105
method_name: str,
106-
data: Union[bytes, str, GrpcMessage],
106+
data: Union[bytes, str, GrpcMessage] = b'',
107107
content_type: Optional[str] = None,
108108
metadata: Optional[MetadataTuple] = None,
109109
http_verb: Optional[str] = None,

dapr/aio/clients/grpc/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import time
2020
import uuid
2121
from datetime import datetime
22-
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Text, Union
22+
from typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Text, Tuple, Union
2323
from urllib.parse import urlencode
2424
from warnings import warn
2525

@@ -154,7 +154,7 @@ def __init__(
154154

155155
useragent = f'dapr-sdk-python/{__version__}'
156156
if not max_grpc_message_length:
157-
options = [
157+
options: List[Tuple[str, Any]] = [
158158
('grpc.primary_user_agent', useragent),
159159
]
160160
else:
@@ -205,7 +205,7 @@ def __init__(
205205

206206
@staticmethod
207207
def get_credentials():
208-
return grpc.ssl_channel_credentials()
208+
return grpc.ssl_channel_credentials() # type: ignore[attr-defined]
209209

210210
async def close(self):
211211
"""Closes Dapr runtime gRPC channel."""
@@ -604,7 +604,7 @@ async def subscribe_with_handler(
604604
self,
605605
pubsub_name: str,
606606
topic: str,
607-
handler_fn: Callable[..., TopicEventResponse],
607+
handler_fn: Callable[..., Awaitable[TopicEventResponse]],
608608
metadata: Optional[dict] = None,
609609
dead_letter_topic: Optional[str] = None,
610610
) -> Callable[[], Awaitable[None]]:
@@ -1020,7 +1020,7 @@ async def execute_state_transaction(
10201020
operationType=o.operation_type.value,
10211021
request=common_v1.StateItem(
10221022
key=o.key,
1023-
value=to_bytes(o.data),
1023+
value=to_bytes(o.data) if o.data is not None else to_bytes(''),
10241024
etag=common_v1.Etag(value=o.etag) if o.etag is not None else None,
10251025
),
10261026
)
@@ -1360,7 +1360,7 @@ async def try_lock(
13601360
response = await call
13611361
return TryLockResponse(
13621362
success=response.success,
1363-
client=self,
1363+
client=self, # type: ignore[arg-type]
13641364
store_name=store_name,
13651365
resource_id=resource_id,
13661366
lock_owner=lock_owner,
@@ -1697,7 +1697,7 @@ async def raise_workflow_event(
16971697
else:
16981698
encoded_data = bytes([])
16991699
# Actual workflow raise event invocation
1700-
req = api_v1.raise_workflow_event(
1700+
req = api_v1.RaiseEventWorkflowRequest(
17011701
instance_id=instance_id,
17021702
workflow_component=workflow_component,
17031703
event_name=event_name,

dapr/aio/clients/grpc/interceptors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ async def _intercept_call(self, client_call_details: ClientCallDetails) -> Clien
9292
:class: `ClientCallDetails` modified call details
9393
"""
9494

95-
metadata = []
95+
metadata: List[Tuple[str, str]] = []
9696
if client_call_details.metadata is not None:
97-
metadata = list(client_call_details.metadata)
97+
metadata = list(client_call_details.metadata) # type: ignore[arg-type]
9898
metadata.extend(self._metadata)
9999

100100
new_call_details = _ClientCallDetailsAsync(

dapr/aio/clients/grpc/subscription.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22

3-
from grpc import StatusCode
3+
from grpc import StatusCode # type: ignore[attr-defined]
44
from grpc.aio import AioRpcError
55

66
from dapr.aio.clients.health import DaprHealth
@@ -21,7 +21,7 @@ def __init__(self, stub, pubsub_name, topic, metadata=None, dead_letter_topic=No
2121
self._metadata = metadata or {}
2222
self._dead_letter_topic = dead_letter_topic or ''
2323
self._stream = None
24-
self._send_queue = asyncio.Queue()
24+
self._send_queue: asyncio.Queue[api_v1.SubscribeTopicEventsRequestAlpha1] = asyncio.Queue()
2525
self._stream_active = asyncio.Event()
2626

2727
async def start(self):

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ non_interactive = True
99

1010
files =
1111
dapr/actor/**/*.py,
12+
dapr/aio/**/*.py,
1213
dapr/clients/**/*.py,
1314
dapr/conf/**/*.py,
1415
dapr/serializers/**/*.py,

0 commit comments

Comments
 (0)