Skip to content

Commit 4ac2a37

Browse files
authored
[EG] next-mypy (Azure#31857)
* next-mypy * fix analyze * update typing * update comments * remove Any
1 parent e2b73c7 commit 4ac2a37

File tree

10 files changed

+40
-27
lines changed

10 files changed

+40
-27
lines changed

sdk/eventgrid/azure-eventgrid/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ For example, you can use `DefaultAzureCredential` to construct a client which wi
6060
from azure.identity import DefaultAzureCredential
6161
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
6262

63-
credential = DefaultAzureCredential()
63+
default_az_credential = DefaultAzureCredential()
6464
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
65-
client = EventGridPublisherClient(endpoint, credential)
65+
client = EventGridPublisherClient(endpoint, default_az_credential)
6666
```
6767

6868
<!-- END SNIPPET -->
@@ -88,8 +88,8 @@ from azure.core.credentials import AzureKeyCredential
8888
topic_key = os.environ["EVENTGRID_TOPIC_KEY"]
8989
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
9090

91-
credential = AzureKeyCredential(topic_key)
92-
client = EventGridPublisherClient(endpoint, credential)
91+
credential_key = AzureKeyCredential(topic_key)
92+
client = EventGridPublisherClient(endpoint, credential_key)
9393
```
9494

9595
<!-- END SNIPPET -->

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
5-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING, Any, Dict
66
import json
77
import hashlib
88
import hmac
@@ -165,13 +165,13 @@ def _from_cncf_events(event): # pylint: disable=inconsistent-return-statements
165165

166166
def _build_request(endpoint, content_type, events, *, channel_name=None):
167167
serialize = Serializer()
168-
header_parameters = {} # type: Dict[str, Any]
168+
header_parameters: Dict[str, Any] = {}
169169
header_parameters['Content-Type'] = serialize.header("content_type", content_type, 'str')
170170

171171
if channel_name:
172172
header_parameters['aeg-channel-name'] = channel_name
173173

174-
query_parameters = {} # type: Dict[str, Any]
174+
query_parameters: Dict[str, Any] = {}
175175
query_parameters['api-version'] = serialize.query("api_version", "2018-01-01", 'str')
176176

177177
body = serialize.body(events, '[object]')

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@
5454
TokenCredential,
5555
)
5656

57+
from cloudevents.http.event import CloudEvent as CNCFCloudEvent
58+
5759
SendType = Union[
5860
CloudEvent,
5961
EventGridEvent,
6062
Dict,
63+
"CNCFCloudEvent",
6164
List[CloudEvent],
6265
List[EventGridEvent],
6366
List[Dict],
67+
List["CNCFCloudEvent"],
6468
]
6569

6670
ListEventType = Union[List[CloudEvent], List[EventGridEvent], List[Dict]]

sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@
4848
if TYPE_CHECKING:
4949
from azure.core.credentials_async import AsyncTokenCredential
5050

51+
from cloudevents.http.event import CloudEvent as CNCFCloudEvent
52+
5153
SendType = Union[
52-
CloudEvent, EventGridEvent, Dict, List[CloudEvent], List[EventGridEvent], List[Dict]
54+
CloudEvent,
55+
EventGridEvent,
56+
Dict,
57+
"CNCFCloudEvent",
58+
List[CloudEvent],
59+
List[EventGridEvent],
60+
List[Dict],
61+
List["CNCFCloudEvent"],
5362
]
5463

5564
ListEventType = Union[List[CloudEvent], List[EventGridEvent], List[Dict]]

sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_authentication_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
topic_key = os.environ["EVENTGRID_TOPIC_KEY"]
2424
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
2525

26-
credential = AzureKeyCredential(topic_key)
27-
client = EventGridPublisherClient(endpoint, credential)
26+
credential_key = AzureKeyCredential(topic_key)
27+
client = EventGridPublisherClient(endpoint, credential_key)
2828
# [END client_auth_with_key_cred_async]
2929

3030
# [START client_auth_with_sas_cred_async]
@@ -35,8 +35,8 @@
3535
signature = os.environ["EVENTGRID_SAS"]
3636
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
3737

38-
credential = AzureSasCredential(signature)
39-
client = EventGridPublisherClient(endpoint, credential)
38+
credential_sas = AzureSasCredential(signature)
39+
client = EventGridPublisherClient(endpoint, credential_sas)
4040
# [END client_auth_with_sas_cred_async]
4141

4242
# [START client_auth_with_token_cred_async]
@@ -51,7 +51,7 @@
5151
data_version="2.0"
5252
)
5353

54-
credential = DefaultAzureCredential()
54+
default_az_credential = DefaultAzureCredential()
5555
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
56-
client = EventGridPublisherClient(endpoint, credential)
56+
client = EventGridPublisherClient(endpoint, default_az_credential)
5757
# [END client_auth_with_token_cred_async]

sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CONNECTION_STR = os.environ["EVENT_HUB_CONN_STR"]
2626
EVENTHUB_NAME = os.environ["EVENT_HUB_NAME"]
2727
def on_event(partition_context, event):
28-
dict_event = CloudEvent.from_json(event)
28+
dict_event: CloudEvent = CloudEvent.from_json(event)
2929
print("data: {}\n".format(dict_event.data))
3030

3131
consumer_client = EventHubConsumerClient.from_connection_string(

sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_storage_queue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1) STORAGE_QUEUE_CONN_STR: The connection string to the Storage account
1414
3) STORAGE_QUEUE_NAME: The name of the storage queue.
1515
"""
16-
16+
from typing import List
1717
from azure.core.messaging import CloudEvent
1818
from azure.storage.queue import QueueServiceClient, BinaryBase64DecodePolicy
1919
import os
@@ -30,7 +30,7 @@
3030
).peek_messages(max_messages=32)
3131

3232
## deserialize payload into a list of typed Events
33-
events = [CloudEvent.from_json(msg) for msg in payload]
33+
events: List[CloudEvent] = [CloudEvent.from_json(msg) for msg in payload]
3434

3535
for event in events:
3636
print(type(event)) ## CloudEvent

sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from azure.core.messaging import CloudEvent
2424
from azure.eventgrid import EventGridPublisherClient
2525

26-
key = os.environ.get("EVENTGRID_CLOUD_EVENT_TOPIC_KEY")
26+
key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"]
2727
endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"]
2828

2929
# authenticate client

sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_authentication.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
topic_key = os.environ["EVENTGRID_TOPIC_KEY"]
2424
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
2525

26-
credential = AzureKeyCredential(topic_key)
27-
client = EventGridPublisherClient(endpoint, credential)
26+
credential_key = AzureKeyCredential(topic_key)
27+
client = EventGridPublisherClient(endpoint, credential_key)
2828
# [END client_auth_with_key_cred]
2929

3030
# [START client_auth_with_sas_cred]
@@ -35,15 +35,15 @@
3535
signature = os.environ["EVENTGRID_SAS"]
3636
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
3737

38-
credential = AzureSasCredential(signature)
39-
client = EventGridPublisherClient(endpoint, credential)
38+
credential_sas = AzureSasCredential(signature)
39+
client = EventGridPublisherClient(endpoint, credential_sas)
4040
# [END client_auth_with_sas_cred]
4141

4242
# [START client_auth_with_token_cred]
4343
from azure.identity import DefaultAzureCredential
4444
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
4545

46-
credential = DefaultAzureCredential()
46+
default_az_credential = DefaultAzureCredential()
4747
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
48-
client = EventGridPublisherClient(endpoint, credential)
48+
client = EventGridPublisherClient(endpoint, default_az_credential)
4949
# [END client_auth_with_token_cred]

sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"""
77
FILE: sample_consume_custom_payload.py
88
DESCRIPTION:
9-
These samples demonstrate consuming a raw json with a list of jsons and
9+
These samples demonstrate consuming a raw json with a list of json and
1010
deserializing them into typed objects of CloudEvents.
1111
USAGE:
1212
python sample_consume_custom_payload.py
1313
"""
14-
14+
from typing import List
1515
from azure.core.messaging import CloudEvent
1616
import json
1717

@@ -27,7 +27,7 @@
2727
"specversion":"1.0"
2828
}]"""
2929

30-
deserialized_dict_events = [CloudEvent(**msg) for msg in json.loads(cloud_custom_dict)]
30+
deserialized_dict_events: List[CloudEvent] = [CloudEvent(**msg) for msg in json.loads(cloud_custom_dict)]
3131

3232
for event in deserialized_dict_events:
3333
print(event.data)

0 commit comments

Comments
 (0)