Skip to content

Commit 22cc32f

Browse files
[AppConfig] mypy fixes (Azure#18858)
closes Azure#18540
1 parent 7849a11 commit 22cc32f

File tree

8 files changed

+75
-56
lines changed

8 files changed

+75
-56
lines changed

eng/tox/mypy_hard_failure_packages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"azure-ai-formrecognizer",
1616
"azure-ai-metricsadvisor",
1717
"azure-eventgrid",
18+
"azure-appconfiguration",
1819
"azure-data-tables",
1920
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# license information.
55
# -------------------------------------------------------------------------
66
import binascii
7-
from typing import Optional, Any
7+
from typing import Optional, Any, Mapping, Union
88
from requests.structures import CaseInsensitiveDict
99
from azure.core import MatchConditions
1010
from azure.core.pipeline import Pipeline
@@ -83,8 +83,6 @@ def __init__(self, base_url, credential, **kwargs):
8383
)
8484
self._sync_token_policy = SyncTokenPolicy()
8585

86-
self._sync_token_policy = None
87-
8886
pipeline = kwargs.get("pipeline")
8987

9088
if pipeline is None:
@@ -204,7 +202,7 @@ def list_configuration_settings(
204202
error_map = {401: ClientAuthenticationError}
205203

206204
try:
207-
return self._impl.get_key_values(
205+
return self._impl.get_key_values( # type: ignore
208206
label=label_filter,
209207
key=key_filter,
210208
select=select,
@@ -223,12 +221,12 @@ def list_configuration_settings(
223221
@distributed_trace
224222
def get_configuration_setting(
225223
self,
226-
key,
227-
label=None,
228-
etag="*",
229-
match_condition=MatchConditions.Unconditionally,
230-
**kwargs
231-
): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> ConfigurationSetting
224+
key, # type: str
225+
label=None, # type: Optional[str]
226+
etag="*", # type: Optional[str]
227+
match_condition=MatchConditions.Unconditionally, # type: Optional[MatchConditions]
228+
**kwargs # type: Any
229+
): # type: (...) -> Union[None, ConfigurationSetting]
232230

233231
"""Get the matched ConfigurationSetting from Azure App Configuration service
234232
@@ -310,12 +308,12 @@ def add_configuration_setting(self, configuration_setting, **kwargs):
310308
added_config_setting = client.add_configuration_setting(config_setting)
311309
"""
312310
key_value = configuration_setting._to_generated()
313-
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
311+
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
314312
error_map = {401: ClientAuthenticationError, 412: ResourceExistsError}
315313
try:
316314
key_value_added = self._impl.put_key_value(
317315
entity=key_value,
318-
key=key_value.key,
316+
key=key_value.key, # type: ignore
319317
label=key_value.label,
320318
if_none_match="*",
321319
headers=custom_headers,
@@ -366,7 +364,7 @@ def set_configuration_setting(
366364
returned_config_setting = client.set_configuration_setting(config_setting)
367365
"""
368366
key_value = configuration_setting._to_generated()
369-
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
367+
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
370368
error_map = {401: ClientAuthenticationError, 409: ResourceReadOnlyError}
371369
if match_condition == MatchConditions.IfNotModified:
372370
error_map[412] = ResourceModifiedError
@@ -380,7 +378,7 @@ def set_configuration_setting(
380378
try:
381379
key_value_set = self._impl.put_key_value(
382380
entity=key_value,
383-
key=key_value.key,
381+
key=key_value.key, # type: ignore
384382
label=key_value.label,
385383
if_match=prep_if_match(configuration_setting.etag, match_condition),
386384
if_none_match=prep_if_none_match(
@@ -426,7 +424,7 @@ def delete_configuration_setting(self, key, label=None, **kwargs):
426424
"""
427425
etag = kwargs.pop("etag", None)
428426
match_condition = kwargs.pop("match_condition", MatchConditions.Unconditionally)
429-
custom_headers = CaseInsensitiveDict(kwargs.get("headers"))
427+
custom_headers = CaseInsensitiveDict(kwargs.get("headers")) # type: Mapping[str, Any]
430428
error_map = {401: ClientAuthenticationError, 409: ResourceReadOnlyError}
431429
if match_condition == MatchConditions.IfNotModified:
432430
error_map[412] = ResourceModifiedError
@@ -445,7 +443,7 @@ def delete_configuration_setting(self, key, label=None, **kwargs):
445443
headers=custom_headers,
446444
error_map=error_map,
447445
)
448-
return ConfigurationSetting._from_generated(key_value_deleted)
446+
return ConfigurationSetting._from_generated(key_value_deleted) # type: ignore
449447
except HttpResponseError as error:
450448
e = error_map[error.status_code]
451449
raise e(message=error.message, response=error.response)
@@ -496,7 +494,7 @@ def list_revisions(self, key_filter=None, label_filter=None, **kwargs):
496494
error_map = {401: ClientAuthenticationError}
497495

498496
try:
499-
return self._impl.get_revisions(
497+
return self._impl.get_revisions( # type: ignore
500498
label=label_filter,
501499
key=key_filter,
502500
select=select,

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
from ._generated.models import KeyValue
99

1010

11+
PolymorphicConfigurationSetting = Union[
12+
"ConfigurationSetting", "SecretReferenceConfigurationSetting", "FeatureFlagConfigurationSetting"
13+
]
14+
15+
1116
class ConfigurationSetting(Model):
1217
"""A configuration value.
1318
Variables are only populated by the server, and will be ignored when
@@ -59,14 +64,14 @@ def __init__(self, **kwargs):
5964

6065
@classmethod
6166
def _from_generated(cls, key_value):
62-
# type: (KeyValue) -> ConfigurationSetting
67+
# type: (KeyValue) -> PolymorphicConfigurationSetting
6368
if key_value is None:
64-
return None
69+
return key_value
6570
if key_value.content_type is not None:
6671
try:
6772
if key_value.content_type.startswith(
6873
FeatureFlagConfigurationSetting._feature_flag_content_type # pylint:disable=protected-access
69-
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix):
74+
) and key_value.key.startswith(FeatureFlagConfigurationSetting.key_prefix): # type: ignore
7075
return FeatureFlagConfigurationSetting._from_generated( # pylint: disable=protected-access
7176
key_value
7277
)
@@ -91,7 +96,7 @@ def _from_generated(cls, key_value):
9196
)
9297

9398
def _to_generated(self):
94-
# type: (...) -> KeyValue
99+
# type: () -> KeyValue
95100
return KeyValue(
96101
key=self.key,
97102
label=self.label,
@@ -182,7 +187,7 @@ def enabled(self):
182187

183188
@enabled.setter
184189
def enabled(self, new_value):
185-
# type: (bool) -> bool
190+
# type: (bool) -> None
186191
self._validate()
187192
if self.value is None:
188193
self.value = {}
@@ -215,28 +220,28 @@ def filters(self, new_filters):
215220

216221
@classmethod
217222
def _from_generated(cls, key_value):
218-
# type: (KeyValue) -> FeatureFlagConfigurationSetting
223+
# type: (KeyValue) -> Union[FeatureFlagConfigurationSetting, ConfigurationSetting]
219224
try:
220225
if key_value is None:
221-
return None
226+
return key_value
222227
if key_value.value:
223228
try:
224229
key_value.value = json.loads(key_value.value)
225230
except json.decoder.JSONDecodeError:
226231
pass
227232

228-
filters = key_value.value["conditions"]["client_filters"]
233+
filters = key_value.value["conditions"]["client_filters"] # type: ignore
229234

230235
return cls(
231-
feature_id=key_value.key,
232-
enabled=key_value.value["enabled"],
236+
feature_id=key_value.key, # type: ignore
237+
enabled=key_value.value["enabled"], # type: ignore
233238
label=key_value.label,
234239
content_type=key_value.content_type,
235240
last_modified=key_value.last_modified,
236241
tags=key_value.tags,
237242
read_only=key_value.locked,
238243
etag=key_value.etag,
239-
filters=filters,
244+
filters=filters, # type: ignore
240245
value=key_value.value,
241246
)
242247
except (KeyError, AttributeError):
@@ -273,13 +278,13 @@ class SecretReferenceConfigurationSetting(ConfigurationSetting):
273278
:param content_type:
274279
:type content_type: str
275280
:ivar value: The value of the configuration setting
276-
:vartype value: str
281+
:vartype value: Dict[str, Any]
277282
:ivar last_modified:
278283
:vartype last_modified: datetime
279284
:ivar read_only:
280285
:vartype read_only: bool
281286
:param tags:
282-
:type tags: dict[str, str]
287+
:type tags: Dict[str, str]
283288
"""
284289

285290
_attribute_map = {
@@ -336,16 +341,16 @@ def _validate(self):
336341
def _from_generated(cls, key_value):
337342
# type: (KeyValue) -> SecretReferenceConfigurationSetting
338343
if key_value is None:
339-
return None
344+
return key_value
340345
if key_value.value:
341346
try:
342347
key_value.value = json.loads(key_value.value)
343348
except json.decoder.JSONDecodeError:
344349
pass
345350

346351
return cls(
347-
key=key_value.key,
348-
secret_uri=key_value.value[u"secret_uri"],
352+
key=key_value.key, # type: ignore
353+
secret_uri=key_value.value[u"secret_uri"], # type: ignore
349354
label=key_value.label,
350355
secret_id=key_value.value,
351356
last_modified=key_value.last_modified,
@@ -355,7 +360,7 @@ def _from_generated(cls, key_value):
355360
)
356361

357362
def _to_generated(self):
358-
# type: (...) -> KeyValue
363+
# type: () -> KeyValue
359364
return KeyValue(
360365
key=self.key,
361366
label=self.label,

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_sync_token.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# IN THE SOFTWARE.
2424
#
2525
# --------------------------------------------------------------------------
26+
from typing import Any, Dict
2627
from azure.core.pipeline import PipelineRequest, PipelineResponse
2728
from azure.core.pipeline.policies import SansIOHTTPPolicy
2829

@@ -61,7 +62,7 @@ class SyncTokenPolicy(SansIOHTTPPolicy):
6162
def __init__(self, **kwargs): # pylint: disable=unused-argument
6263
# type: (**Any) -> None
6364
self._sync_token_header = "Sync-Token"
64-
self._sync_tokens = dict()
65+
self._sync_tokens = {} # type: Dict[str, Any]
6566

6667
def on_request(self, request): # type: ignore # pylint: disable=arguments-differ
6768
# type: (PipelineRequest) -> None

sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
# -------------------------------------------------------------------------
66

77
from datetime import datetime
8+
from typing import Optional, Tuple
89
from azure.core import MatchConditions
910

1011

1112
def quote_etag(etag):
13+
# type: (Optional[str]) -> Optional[str]
1214
if not etag or etag == "*":
1315
return etag
1416
if etag.startswith('"') and etag.endswith('"'):
@@ -19,7 +21,7 @@ def quote_etag(etag):
1921

2022

2123
def prep_if_match(etag, match_condition):
22-
# type: (str, MatchConditions) -> str
24+
# type: (Optional[str], Optional[MatchConditions]) -> Optional[str]
2325
if match_condition == MatchConditions.IfNotModified:
2426
if_match = quote_etag(etag) if etag else None
2527
return if_match
@@ -29,7 +31,7 @@ def prep_if_match(etag, match_condition):
2931

3032

3133
def prep_if_none_match(etag, match_condition):
32-
# type: (str, MatchConditions) -> str
34+
# type: (Optional[str], Optional[MatchConditions]) -> Optional[str]
3335
if match_condition == MatchConditions.IfModified:
3436
if_none_match = quote_etag(etag) if etag else None
3537
return if_none_match
@@ -39,11 +41,13 @@ def prep_if_none_match(etag, match_condition):
3941

4042

4143
def get_endpoint_from_connection_string(connection_string):
44+
# type: (str) -> str
4245
endpoint, _, _ = parse_connection_string(connection_string)
4346
return endpoint
4447

4548

4649
def parse_connection_string(connection_string):
50+
# type: (str) -> Tuple[str, str, str]
4751
# connection_string looks like Endpoint=https://xxxxx;Id=xxxxx;Secret=xxxx
4852
segments = connection_string.split(";")
4953
if len(segments) != 3:
@@ -70,4 +74,5 @@ def parse_connection_string(connection_string):
7074

7175

7276
def get_current_utc_time():
77+
# type: () -> str
7378
return str(datetime.utcnow().strftime("%b, %d %Y %H:%M:%S.%f ")) + "GMT"

0 commit comments

Comments
 (0)