Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppConfig] mypy fixes #18858

Merged
5 commits merged into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/tox/mypy_hard_failure_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
"azure-ai-formrecognizer",
"azure-ai-metricsadvisor",
"azure-eventgrid",
"azure-appconfiguration"
]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# license information.
# -------------------------------------------------------------------------
import binascii
from typing import Optional, Any
from typing import Optional, Any, Mapping
from requests.structures import CaseInsensitiveDict
from azure.core import MatchConditions
from azure.core.pipeline import Pipeline
Expand Down Expand Up @@ -83,8 +83,6 @@ def __init__(self, base_url, credential, **kwargs):
)
self._sync_token_policy = SyncTokenPolicy()

self._sync_token_policy = None

pipeline = kwargs.get("pipeline")

if pipeline is None:
Expand Down Expand Up @@ -204,7 +202,7 @@ def list_configuration_settings(
error_map = {401: ClientAuthenticationError}

try:
return self._impl.get_key_values(
return self._impl.get_key_values( # type: ignore
label=label_filter,
key=key_filter,
select=select,
Expand All @@ -228,7 +226,7 @@ def get_configuration_setting(
etag="*",
match_condition=MatchConditions.Unconditionally,
**kwargs
): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> ConfigurationSetting
): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Optional[ConfigurationSetting]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd to me. Is there a way that you can call this method and it will return None instead of a ConfigurationSetting? This could almost be considered a breaking change if we used to document this as always returning a ConfigurationSetting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch


"""Get the matched ConfigurationSetting from Azure App Configuration service

Expand Down Expand Up @@ -285,7 +283,7 @@ def get_configuration_setting(

@distributed_trace
def add_configuration_setting(self, configuration_setting, **kwargs):
# type: (ConfigurationSetting, **Any) -> ConfigurationSetting
# type: (ConfigurationSetting, **Any) -> Optional[ConfigurationSetting]

"""Add a ConfigurationSetting instance into the Azure App Configuration service.

Expand All @@ -310,12 +308,12 @@ def add_configuration_setting(self, configuration_setting, **kwargs):
added_config_setting = client.add_configuration_setting(config_setting)
"""
key_value = configuration_setting._to_generated()
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
error_map = {401: ClientAuthenticationError, 412: ResourceExistsError}
try:
key_value_added = self._impl.put_key_value(
entity=key_value,
key=key_value.key,
key=key_value.key, # type: ignore
label=key_value.label,
if_none_match="*",
headers=custom_headers,
Expand All @@ -334,7 +332,7 @@ def set_configuration_setting(
configuration_setting,
match_condition=MatchConditions.Unconditionally,
**kwargs
): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> ConfigurationSetting
): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> Optional[ConfigurationSetting]

"""Add or update a ConfigurationSetting.
If the configuration setting identified by key and label does not exist, this is a create.
Expand Down Expand Up @@ -366,7 +364,7 @@ def set_configuration_setting(
returned_config_setting = client.set_configuration_setting(config_setting)
"""
key_value = configuration_setting._to_generated()
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
error_map = {401: ClientAuthenticationError, 409: ResourceReadOnlyError}
if match_condition == MatchConditions.IfNotModified:
error_map[412] = ResourceModifiedError
Expand All @@ -380,7 +378,7 @@ def set_configuration_setting(
try:
key_value_set = self._impl.put_key_value(
entity=key_value,
key=key_value.key,
key=key_value.key, # type: ignore
label=key_value.label,
if_match=prep_if_match(configuration_setting.etag, match_condition),
if_none_match=prep_if_none_match(
Expand All @@ -398,7 +396,7 @@ def set_configuration_setting(

@distributed_trace
def delete_configuration_setting(self, key, label=None, **kwargs):
# type: (str, Optional[str], **Any) -> ConfigurationSetting
# type: (str, Optional[str], **Any) -> Optional[ConfigurationSetting]

"""Delete a ConfigurationSetting if it exists

Expand Down Expand Up @@ -426,7 +424,7 @@ def delete_configuration_setting(self, key, label=None, **kwargs):
"""
etag = kwargs.pop("etag", None)
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
error_map = {401: ClientAuthenticationError, 409: ResourceReadOnlyError}
if match_condition == MatchConditions.IfNotModified:
error_map[412] = ResourceModifiedError
Expand All @@ -445,7 +443,7 @@ def delete_configuration_setting(self, key, label=None, **kwargs):
headers=custom_headers,
error_map=error_map,
)
return ConfigurationSetting._from_generated(key_value_deleted)
return ConfigurationSetting._from_generated(key_value_deleted) # type: ignore
except HttpResponseError as error:
e = error_map[error.status_code]
raise e(message=error.message, response=error.response)
Expand Down Expand Up @@ -496,7 +494,7 @@ def list_revisions(self, key_filter=None, label_filter=None, **kwargs):
error_map = {401: ClientAuthenticationError}

try:
return self._impl.get_revisions(
return self._impl.get_revisions( # type: ignore
label=label_filter,
key=key_filter,
select=select,
Expand All @@ -514,7 +512,7 @@ def list_revisions(self, key_filter=None, label_filter=None, **kwargs):

@distributed_trace
def set_read_only(self, configuration_setting, read_only=True, **kwargs):
# type: (ConfigurationSetting, Optional[bool], **Any) -> ConfigurationSetting
# type: (ConfigurationSetting, Optional[bool], **Any) -> Optional[ConfigurationSetting]

"""Set a configuration setting read only

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_keys(
name: Optional[str] = None,
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
**kwargs
**kwargs: Any
) -> AsyncIterable["_models.KeyListResult"]:
"""Gets a list of keys.

Expand Down Expand Up @@ -117,7 +117,7 @@ async def check_keys(
name: Optional[str] = None,
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
**kwargs
**kwargs: Any
) -> None:
"""Requests the headers and status of the given resource.

Expand Down Expand Up @@ -188,7 +188,7 @@ def get_key_values(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[Union[str, "_models.Get6ItemsItem"]]] = None,
**kwargs
**kwargs: Any
) -> AsyncIterable["_models.KeyValueListResult"]:
"""Gets a list of key-values.

Expand Down Expand Up @@ -290,7 +290,7 @@ async def check_key_values(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[Union[str, "_models.Head6ItemsItem"]]] = None,
**kwargs
**kwargs: Any
) -> None:
"""Requests the headers and status of the given resource.

Expand Down Expand Up @@ -370,7 +370,7 @@ async def get_key_value(
if_match: Optional[str] = None,
if_none_match: Optional[str] = None,
select: Optional[List[Union[str, "_models.Get7ItemsItem"]]] = None,
**kwargs
**kwargs: Any
) -> "_models.KeyValue":
"""Gets a single key-value.

Expand Down Expand Up @@ -460,7 +460,7 @@ async def put_key_value(
if_match: Optional[str] = None,
if_none_match: Optional[str] = None,
entity: Optional["_models.KeyValue"] = None,
**kwargs
**kwargs: Any
) -> "_models.KeyValue":
"""Creates a key-value.

Expand Down Expand Up @@ -548,7 +548,7 @@ async def delete_key_value(
key: str,
label: Optional[str] = None,
if_match: Optional[str] = None,
**kwargs
**kwargs: Any
) -> Optional["_models.KeyValue"]:
"""Deletes a key-value.

Expand Down Expand Up @@ -629,7 +629,7 @@ async def check_key_value(
if_match: Optional[str] = None,
if_none_match: Optional[str] = None,
select: Optional[List[Union[str, "_models.Head7ItemsItem"]]] = None,
**kwargs
**kwargs: Any
) -> None:
"""Requests the headers and status of the given resource.

Expand Down Expand Up @@ -713,7 +713,7 @@ def get_labels(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[str]] = None,
**kwargs
**kwargs: Any
) -> AsyncIterable["_models.LabelListResult"]:
"""Gets a list of labels.

Expand Down Expand Up @@ -810,7 +810,7 @@ async def check_labels(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[str]] = None,
**kwargs
**kwargs: Any
) -> None:
"""Requests the headers and status of the given resource.

Expand Down Expand Up @@ -884,7 +884,7 @@ async def put_lock(
label: Optional[str] = None,
if_match: Optional[str] = None,
if_none_match: Optional[str] = None,
**kwargs
**kwargs: Any
) -> "_models.KeyValue":
"""Locks a key-value.

Expand Down Expand Up @@ -963,7 +963,7 @@ async def delete_lock(
label: Optional[str] = None,
if_match: Optional[str] = None,
if_none_match: Optional[str] = None,
**kwargs
**kwargs: Any
) -> "_models.KeyValue":
"""Unlocks a key-value.

Expand Down Expand Up @@ -1043,7 +1043,7 @@ def get_revisions(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[Union[str, "_models.Enum4"]]] = None,
**kwargs
**kwargs: Any
) -> AsyncIterable["_models.KeyValueListResult"]:
"""Gets a list of key-value revisions.

Expand Down Expand Up @@ -1145,7 +1145,7 @@ async def check_revisions(
after: Optional[str] = None,
accept_datetime: Optional[str] = None,
select: Optional[List[Union[str, "_models.Enum5"]]] = None,
**kwargs
**kwargs: Any
) -> None:
"""Requests the headers and status of the given resource.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
import json
from typing import Dict, Optional, Any, List, Union
from typing import Dict, Optional, Any, List, Union, Optional, Mapping
from msrest.serialization import Model
from ._generated.models import KeyValue

Expand Down Expand Up @@ -59,14 +59,14 @@ def __init__(self, **kwargs):

@classmethod
def _from_generated(cls, key_value):
# type: (KeyValue) -> ConfigurationSetting
# type: (KeyValue) -> Optional[ConfigurationSetting]
if key_value is None:
return None
return key_value
if key_value.content_type is not None:
try:
if key_value.content_type.startswith(
FeatureFlagConfigurationSetting._feature_flag_content_type # pylint:disable=protected-access
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix):
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix): # type: ignore
return FeatureFlagConfigurationSetting._from_generated( # pylint: disable=protected-access
key_value
)
Expand All @@ -91,7 +91,7 @@ def _from_generated(cls, key_value):
)

def _to_generated(self):
# type: (...) -> KeyValue
# type: () -> KeyValue
return KeyValue(
key=self.key,
label=self.label,
Expand Down Expand Up @@ -182,7 +182,7 @@ def enabled(self):

@enabled.setter
def enabled(self, new_value):
# type: (bool) -> bool
# type: (bool) -> None
self._validate()
if self.value is None:
self.value = {}
Expand Down Expand Up @@ -215,28 +215,28 @@ def filters(self, new_filters):

@classmethod
def _from_generated(cls, key_value):
# type: (KeyValue) -> FeatureFlagConfigurationSetting
# type: (KeyValue) -> Optional[Union[FeatureFlagConfigurationSetting, ConfigurationSetting]]
try:
if key_value is None:
return None
return key_value
if key_value.value:
try:
key_value.value = json.loads(key_value.value)
except json.decoder.JSONDecodeError:
pass

filters = key_value.value["conditions"]["client_filters"]
filters = key_value.value["conditions"]["client_filters"] # type: ignore

return cls(
feature_id=key_value.key,
enabled=key_value.value["enabled"],
feature_id=key_value.key, # type: ignore
enabled=key_value.value["enabled"], # type: ignore
label=key_value.label,
content_type=key_value.content_type,
last_modified=key_value.last_modified,
tags=key_value.tags,
read_only=key_value.locked,
etag=key_value.etag,
filters=filters,
filters=filters, # type: ignore
value=key_value.value,
)
except (KeyError, AttributeError):
Expand Down Expand Up @@ -273,13 +273,13 @@ class SecretReferenceConfigurationSetting(ConfigurationSetting):
:param content_type:
:type content_type: str
:ivar value: The value of the configuration setting
:vartype value: str
:vartype value: Dict[str, Any]
:ivar last_modified:
:vartype last_modified: datetime
:ivar read_only:
:vartype read_only: bool
:param tags:
:type tags: dict[str, str]
:type tags: Dict[str, str]
"""

_attribute_map = {
Expand Down Expand Up @@ -336,16 +336,16 @@ def _validate(self):
def _from_generated(cls, key_value):
# type: (KeyValue) -> SecretReferenceConfigurationSetting
if key_value is None:
return None
return key_value
if key_value.value:
try:
key_value.value = json.loads(key_value.value)
except json.decoder.JSONDecodeError:
pass

return cls(
key=key_value.key,
secret_uri=key_value.value[u"secret_uri"],
key=key_value.key, # type: ignore
secret_uri=key_value.value[u"secret_uri"], # type: ignore
label=key_value.label,
secret_id=key_value.value,
last_modified=key_value.last_modified,
Expand All @@ -355,7 +355,7 @@ def _from_generated(cls, key_value):
)

def _to_generated(self):
# type: (...) -> KeyValue
# type: () -> KeyValue
return KeyValue(
key=self.key,
label=self.label,
Expand Down
Loading