Skip to content

Commit 835adb3

Browse files
update pinned mypy version (Azure#23171)
* update mypy pinned version to 0.931 and include types deps * update mypy checks to be run with python 3.10 in CI * let mypy install the third-party package stubs it needs at runtime * pin type stub versions needed and update ignore flag * [ServiceBus&EventHubs] fix mypy 0.931 errors (Azure#23017) * fix mypy 0.931 errors * update tuple naming * fix mypy errors with latest version of mypy (Azure#23093) * correct mypy errors arising from latest mypy version (Azure#23114) Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
1 parent 772a7cf commit 835adb3

File tree

10 files changed

+27
-16
lines changed

10 files changed

+27
-16
lines changed

eng/pipelines/templates/steps/run_mypy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ parameters:
1212
# Please use `$(TargetingString)` to refer to the python packages glob string. This was previously `${{ parameters.BuildTargetingString }}`.
1313
steps:
1414
- task: UsePythonVersion@0
15-
displayName: 'Use Python 3.7'
15+
displayName: 'Use Python 3.10'
1616
inputs:
17-
versionSpec: '3.7'
17+
versionSpec: '3.10'
1818
condition: and(succeededOrFailed(), ne(variables['Skip.MyPy'],'true'))
1919

2020
- script: |

eng/tox/run_mypy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
sys.executable,
4141
"-m",
4242
"mypy",
43-
"--ignore-missing",
43+
"--ignore-missing-imports",
4444
os.path.join(args.target_package, "azure"),
4545
]
4646
)

eng/tox/tox.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ setenv =
9999
PROXY_URL=http://localhost:5003
100100
deps =
101101
{[base]deps}
102-
mypy==0.782; python_version >= '3.5'
102+
mypy==0.931
103+
types-chardet==4.0.3
104+
types-requests==2.27.9
105+
types-six==1.16.10
103106
commands =
104107
{envbindir}/python {toxinidir}/../../../eng/tox/run_mypy.py -t {toxinidir}
105108

sdk/core/azure-core/azure/core/_pipeline_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
# --------------------------------------------------------------------------
2626

2727
import logging
28-
try:
29-
from collections.abc import Iterable
30-
except ImportError:
31-
from collections import Iterable
28+
from collections.abc import Iterable
3229
from .configuration import Configuration
3330
from .pipeline import Pipeline
3431
from .pipeline.transport._base import PipelineClientBase

sdk/core/azure-core/azure/core/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def convert_tracing_impl(value):
161161
return get_opencensus_span_if_opencensus_is_imported()
162162

163163
if not isinstance(value, six.string_types):
164+
value = cast(Type[AbstractSpan], value)
164165
return value
165166

166167
value = cast(str, value) # mypy clarity

sdk/eventhub/azure-eventhub/azure/eventhub/_client_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
from azure.core.credentials import TokenCredential
4747

4848
_LOGGER = logging.getLogger(__name__)
49-
_Address = collections.namedtuple("Address", "hostname path")
49+
_Address = collections.namedtuple("_Address", "hostname path")
5050

5151

5252
def _parse_conn_str(conn_str, **kwargs):

sdk/metricsadvisor/azure-ai-metricsadvisor/azure/ai/metricsadvisor/_metrics_advisor_administration_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def refresh_data_feed_ingestion(
640640

641641
@distributed_trace
642642
def delete_alert_configuration(self, *alert_configuration_id, **kwargs):
643-
# type: (*str, Any) -> None
643+
# type: (str, Any) -> None
644644
"""Delete an anomaly alert configuration by its ID.
645645
646646
:param str alert_configuration_id: anomaly alert configuration unique id.
@@ -666,7 +666,7 @@ def delete_alert_configuration(self, *alert_configuration_id, **kwargs):
666666

667667
@distributed_trace
668668
def delete_detection_configuration(self, *detection_configuration_id, **kwargs):
669-
# type: (*str, Any) -> None
669+
# type: (str, Any) -> None
670670
"""Delete an anomaly detection configuration by its ID.
671671
672672
:param str detection_configuration_id: anomaly detection configuration unique id.
@@ -692,7 +692,7 @@ def delete_detection_configuration(self, *detection_configuration_id, **kwargs):
692692

693693
@distributed_trace
694694
def delete_data_feed(self, *data_feed_id, **kwargs):
695-
# type: (*str, Any) -> None
695+
# type: (str, Any) -> None
696696
"""Delete a data feed by its ID.
697697
698698
:param str data_feed_id: The data feed unique id.
@@ -716,7 +716,7 @@ def delete_data_feed(self, *data_feed_id, **kwargs):
716716

717717
@distributed_trace
718718
def delete_hook(self, *hook_id, **kwargs):
719-
# type: (*str, Any) -> None
719+
# type: (str, Any) -> None
720720
"""Delete a web or email hook by its ID.
721721
722722
:param str hook_id: Hook unique ID.
@@ -844,6 +844,7 @@ def update_data_feed(
844844
data_feed_patch = construct_data_feed_dict(update)
845845

846846
else:
847+
data_feed = cast(DataFeed, data_feed)
847848
data_feed_id = data_feed.id
848849
data_feed_patch_type = DATA_FEED_PATCH[data_feed.source.data_source_type]
849850
data_feed_patch = data_feed._to_generated_patch(
@@ -908,6 +909,7 @@ def update_alert_configuration(
908909
alert_configuration_patch = construct_alert_config_dict(update)
909910

910911
else:
912+
alert_configuration = cast(AnomalyAlertConfiguration, alert_configuration)
911913
alert_configuration_id = alert_configuration.id
912914
alert_configuration_patch = alert_configuration._to_generated_patch(
913915
name=update.pop("name", None),
@@ -985,6 +987,7 @@ def update_detection_configuration(
985987
detection_config_patch = construct_detection_config_dict(update)
986988

987989
else:
990+
detection_configuration = cast(AnomalyDetectionConfiguration, detection_configuration)
988991
detection_configuration_id = detection_configuration.id
989992
detection_config_patch = detection_configuration._to_generated_patch(
990993
name=update.pop("name", None),
@@ -1071,6 +1074,7 @@ def update_hook(
10711074
hook_patch = construct_hook_dict(update, hook_type)
10721075

10731076
else:
1077+
hook = cast(Union[EmailNotificationHook, WebNotificationHook], hook)
10741078
hook_id = hook.id
10751079
if hook.hook_type == "Email":
10761080
hook = cast(EmailNotificationHook, hook)
@@ -1470,7 +1474,7 @@ def update_datasource_credential(
14701474

14711475
@distributed_trace
14721476
def delete_datasource_credential(self, *credential_id, **kwargs):
1473-
# type: (*str, Any) -> None
1477+
# type: (str, Any) -> None
14741478
"""Delete a datasource credential by its ID.
14751479
14761480
:param str credential_id: Datasource credential unique ID.

sdk/metricsadvisor/azure-ai-metricsadvisor/azure/ai/metricsadvisor/aio/_metrics_advisor_administration_client_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ async def update_data_feed(
749749
data_feed_patch = construct_data_feed_dict(update)
750750

751751
else:
752+
data_feed = cast(DataFeed, data_feed)
752753
data_feed_id = data_feed.id
753754
data_feed_patch_type = DATA_FEED_PATCH[data_feed.source.data_source_type]
754755
data_feed_patch = data_feed._to_generated_patch(
@@ -811,6 +812,7 @@ async def update_alert_configuration(
811812
alert_configuration_patch = construct_alert_config_dict(update)
812813

813814
else:
815+
alert_configuration = cast(AnomalyAlertConfiguration, alert_configuration)
814816
alert_configuration_id = alert_configuration.id
815817
alert_configuration_patch = alert_configuration._to_generated_patch(
816818
name=update.pop("name", None),
@@ -887,6 +889,7 @@ async def update_detection_configuration(
887889
detection_config_patch = construct_detection_config_dict(update)
888890

889891
else:
892+
detection_configuration = cast(AnomalyDetectionConfiguration, detection_configuration)
890893
detection_configuration_id = detection_configuration.id
891894
detection_config_patch = detection_configuration._to_generated_patch(
892895
name=update.pop("name", None),
@@ -971,6 +974,7 @@ async def update_hook(
971974
hook_patch = construct_hook_dict(update, hook_type)
972975

973976
else:
977+
hook = cast(Union[EmailNotificationHook, WebNotificationHook], hook)
974978
hook_id = hook.id
975979
if hook.hook_type == "Email":
976980
hook = cast(EmailNotificationHook, hook)

sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import uuid
99
import datetime
1010
import warnings
11-
from typing import Any, List, Optional, Dict, Iterator, Union, TYPE_CHECKING
11+
from typing import Any, List, Optional, Dict, Iterator, Union, TYPE_CHECKING, cast
1212

1313
import six
1414

@@ -692,6 +692,7 @@ def receive_deferred_messages(
692692
raise ValueError("The timeout must be greater than 0.")
693693
if isinstance(sequence_numbers, six.integer_types):
694694
sequence_numbers = [sequence_numbers]
695+
sequence_numbers = cast(List[int], sequence_numbers)
695696
if len(sequence_numbers) == 0:
696697
return [] # no-op on empty list.
697698
self._open()

sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import functools
99
import logging
1010
import warnings
11-
from typing import Any, List, Optional, AsyncIterator, Union, Callable, TYPE_CHECKING
11+
from typing import Any, List, Optional, AsyncIterator, Union, Callable, TYPE_CHECKING, cast
1212

1313
import six
1414

@@ -678,6 +678,7 @@ async def receive_deferred_messages(
678678
raise ValueError("The timeout must be greater than 0.")
679679
if isinstance(sequence_numbers, six.integer_types):
680680
sequence_numbers = [sequence_numbers]
681+
sequence_numbers = cast(List[int], sequence_numbers)
681682
if len(sequence_numbers) == 0:
682683
return [] # no-op on empty list.
683684
await self._open()

0 commit comments

Comments
 (0)