Skip to content

Commit

Permalink
update pinned mypy version (#23171)
Browse files Browse the repository at this point in the history
* 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 (#23017)

* fix mypy 0.931 errors

* update tuple naming

* fix mypy errors with latest version of mypy (#23093)

* correct mypy errors arising from latest mypy version (#23114)

Co-authored-by: swathipil <76007337+swathipil@users.noreply.github.com>
  • Loading branch information
kristapratico and swathipil committed Feb 23, 2022
1 parent 772a7cf commit 835adb3
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions eng/pipelines/templates/steps/run_mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ parameters:
# Please use `$(TargetingString)` to refer to the python packages glob string. This was previously `${{ parameters.BuildTargetingString }}`.
steps:
- task: UsePythonVersion@0
displayName: 'Use Python 3.7'
displayName: 'Use Python 3.10'
inputs:
versionSpec: '3.7'
versionSpec: '3.10'
condition: and(succeededOrFailed(), ne(variables['Skip.MyPy'],'true'))

- script: |
Expand Down
2 changes: 1 addition & 1 deletion eng/tox/run_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
sys.executable,
"-m",
"mypy",
"--ignore-missing",
"--ignore-missing-imports",
os.path.join(args.target_package, "azure"),
]
)
5 changes: 4 additions & 1 deletion eng/tox/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ setenv =
PROXY_URL=http://localhost:5003
deps =
{[base]deps}
mypy==0.782; python_version >= '3.5'
mypy==0.931
types-chardet==4.0.3
types-requests==2.27.9
types-six==1.16.10
commands =
{envbindir}/python {toxinidir}/../../../eng/tox/run_mypy.py -t {toxinidir}

Expand Down
5 changes: 1 addition & 4 deletions sdk/core/azure-core/azure/core/_pipeline_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
# --------------------------------------------------------------------------

import logging
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
from collections.abc import Iterable
from .configuration import Configuration
from .pipeline import Pipeline
from .pipeline.transport._base import PipelineClientBase
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure-core/azure/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def convert_tracing_impl(value):
return get_opencensus_span_if_opencensus_is_imported()

if not isinstance(value, six.string_types):
value = cast(Type[AbstractSpan], value)
return value

value = cast(str, value) # mypy clarity
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/azure-eventhub/azure/eventhub/_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from azure.core.credentials import TokenCredential

_LOGGER = logging.getLogger(__name__)
_Address = collections.namedtuple("Address", "hostname path")
_Address = collections.namedtuple("_Address", "hostname path")


def _parse_conn_str(conn_str, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def refresh_data_feed_ingestion(

@distributed_trace
def delete_alert_configuration(self, *alert_configuration_id, **kwargs):
# type: (*str, Any) -> None
# type: (str, Any) -> None
"""Delete an anomaly alert configuration by its ID.
:param str alert_configuration_id: anomaly alert configuration unique id.
Expand All @@ -666,7 +666,7 @@ def delete_alert_configuration(self, *alert_configuration_id, **kwargs):

@distributed_trace
def delete_detection_configuration(self, *detection_configuration_id, **kwargs):
# type: (*str, Any) -> None
# type: (str, Any) -> None
"""Delete an anomaly detection configuration by its ID.
:param str detection_configuration_id: anomaly detection configuration unique id.
Expand All @@ -692,7 +692,7 @@ def delete_detection_configuration(self, *detection_configuration_id, **kwargs):

@distributed_trace
def delete_data_feed(self, *data_feed_id, **kwargs):
# type: (*str, Any) -> None
# type: (str, Any) -> None
"""Delete a data feed by its ID.
:param str data_feed_id: The data feed unique id.
Expand All @@ -716,7 +716,7 @@ def delete_data_feed(self, *data_feed_id, **kwargs):

@distributed_trace
def delete_hook(self, *hook_id, **kwargs):
# type: (*str, Any) -> None
# type: (str, Any) -> None
"""Delete a web or email hook by its ID.
:param str hook_id: Hook unique ID.
Expand Down Expand Up @@ -844,6 +844,7 @@ def update_data_feed(
data_feed_patch = construct_data_feed_dict(update)

else:
data_feed = cast(DataFeed, data_feed)
data_feed_id = data_feed.id
data_feed_patch_type = DATA_FEED_PATCH[data_feed.source.data_source_type]
data_feed_patch = data_feed._to_generated_patch(
Expand Down Expand Up @@ -908,6 +909,7 @@ def update_alert_configuration(
alert_configuration_patch = construct_alert_config_dict(update)

else:
alert_configuration = cast(AnomalyAlertConfiguration, alert_configuration)
alert_configuration_id = alert_configuration.id
alert_configuration_patch = alert_configuration._to_generated_patch(
name=update.pop("name", None),
Expand Down Expand Up @@ -985,6 +987,7 @@ def update_detection_configuration(
detection_config_patch = construct_detection_config_dict(update)

else:
detection_configuration = cast(AnomalyDetectionConfiguration, detection_configuration)
detection_configuration_id = detection_configuration.id
detection_config_patch = detection_configuration._to_generated_patch(
name=update.pop("name", None),
Expand Down Expand Up @@ -1071,6 +1074,7 @@ def update_hook(
hook_patch = construct_hook_dict(update, hook_type)

else:
hook = cast(Union[EmailNotificationHook, WebNotificationHook], hook)
hook_id = hook.id
if hook.hook_type == "Email":
hook = cast(EmailNotificationHook, hook)
Expand Down Expand Up @@ -1470,7 +1474,7 @@ def update_datasource_credential(

@distributed_trace
def delete_datasource_credential(self, *credential_id, **kwargs):
# type: (*str, Any) -> None
# type: (str, Any) -> None
"""Delete a datasource credential by its ID.
:param str credential_id: Datasource credential unique ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ async def update_data_feed(
data_feed_patch = construct_data_feed_dict(update)

else:
data_feed = cast(DataFeed, data_feed)
data_feed_id = data_feed.id
data_feed_patch_type = DATA_FEED_PATCH[data_feed.source.data_source_type]
data_feed_patch = data_feed._to_generated_patch(
Expand Down Expand Up @@ -811,6 +812,7 @@ async def update_alert_configuration(
alert_configuration_patch = construct_alert_config_dict(update)

else:
alert_configuration = cast(AnomalyAlertConfiguration, alert_configuration)
alert_configuration_id = alert_configuration.id
alert_configuration_patch = alert_configuration._to_generated_patch(
name=update.pop("name", None),
Expand Down Expand Up @@ -887,6 +889,7 @@ async def update_detection_configuration(
detection_config_patch = construct_detection_config_dict(update)

else:
detection_configuration = cast(AnomalyDetectionConfiguration, detection_configuration)
detection_configuration_id = detection_configuration.id
detection_config_patch = detection_configuration._to_generated_patch(
name=update.pop("name", None),
Expand Down Expand Up @@ -971,6 +974,7 @@ async def update_hook(
hook_patch = construct_hook_dict(update, hook_type)

else:
hook = cast(Union[EmailNotificationHook, WebNotificationHook], hook)
hook_id = hook.id
if hook.hook_type == "Email":
hook = cast(EmailNotificationHook, hook)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import uuid
import datetime
import warnings
from typing import Any, List, Optional, Dict, Iterator, Union, TYPE_CHECKING
from typing import Any, List, Optional, Dict, Iterator, Union, TYPE_CHECKING, cast

import six

Expand Down Expand Up @@ -692,6 +692,7 @@ def receive_deferred_messages(
raise ValueError("The timeout must be greater than 0.")
if isinstance(sequence_numbers, six.integer_types):
sequence_numbers = [sequence_numbers]
sequence_numbers = cast(List[int], sequence_numbers)
if len(sequence_numbers) == 0:
return [] # no-op on empty list.
self._open()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import functools
import logging
import warnings
from typing import Any, List, Optional, AsyncIterator, Union, Callable, TYPE_CHECKING
from typing import Any, List, Optional, AsyncIterator, Union, Callable, TYPE_CHECKING, cast

import six

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

0 comments on commit 835adb3

Please sign in to comment.