From 3c78f9fb8e2f8a049a1d77fbd76f879c78a043ba Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 21 May 2021 11:56:26 -0400 Subject: [PATCH 1/4] mypy fixes --- eng/tox/mypy_hard_failure_packages.py | 1 + .../azure-appconfiguration/azure/__init__.py | 2 +- .../_azure_appconfiguration_client.py | 30 ++++++++-------- .../azure/appconfiguration/_models.py | 36 +++++++++---------- .../azure/appconfiguration/_sync_token.py | 3 +- .../azure/appconfiguration/_utils.py | 9 +++-- .../aio/_azure_configuration_client_async.py | 30 ++++++++-------- .../azure-appconfiguration/mypy.ini | 12 +++++++ 8 files changed, 69 insertions(+), 54 deletions(-) create mode 100644 sdk/appconfiguration/azure-appconfiguration/mypy.ini diff --git a/eng/tox/mypy_hard_failure_packages.py b/eng/tox/mypy_hard_failure_packages.py index 8b5f6c93ac31..7c97a3cc1f09 100644 --- a/eng/tox/mypy_hard_failure_packages.py +++ b/eng/tox/mypy_hard_failure_packages.py @@ -14,4 +14,5 @@ "azure-ai-formrecognizer", "azure-ai-metricsadvisor", "azure-eventgrid", + "azure-appconfiguration" ] diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/__init__.py b/sdk/appconfiguration/azure-appconfiguration/azure/__init__.py index 8db66d3d0f0f..d55ccad1f573 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/__init__.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/__init__.py @@ -1 +1 @@ -__path__ = __import__("pkgutil").extend_path(__path__, __name__) +__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py index 2931b1d52348..f8fba66a9d12 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -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 @@ -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: @@ -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, @@ -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] """Get the matched ConfigurationSetting from Azure App Configuration service @@ -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. @@ -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, @@ -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. @@ -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 @@ -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( @@ -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 @@ -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 @@ -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) @@ -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, @@ -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 diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py index 69722cd73b23..44df27866a3c 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py @@ -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 @@ -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 ) @@ -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, @@ -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 = {} @@ -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): @@ -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 = { @@ -336,7 +336,7 @@ 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) @@ -344,8 +344,8 @@ def _from_generated(cls, key_value): 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, @@ -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, diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_sync_token.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_sync_token.py index 9b90854ca6d2..23b9c419eeed 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_sync_token.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_sync_token.py @@ -23,6 +23,7 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +from typing import Any, Dict from azure.core.pipeline import PipelineRequest, PipelineResponse from azure.core.pipeline.policies import SansIOHTTPPolicy @@ -61,7 +62,7 @@ class SyncTokenPolicy(SansIOHTTPPolicy): def __init__(self, **kwargs): # pylint: disable=unused-argument # type: (**Any) -> None self._sync_token_header = "Sync-Token" - self._sync_tokens = dict() + self._sync_tokens = {} # type: Dict[str, Any] def on_request(self, request): # type: ignore # pylint: disable=arguments-differ # type: (PipelineRequest) -> None diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py index fb7542758250..3ff02d4a1d47 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_utils.py @@ -5,10 +5,12 @@ # ------------------------------------------------------------------------- from datetime import datetime +from typing import Optional, Tuple from azure.core import MatchConditions def quote_etag(etag): + # type: (Optional[str]) -> Optional[str] if not etag or etag == "*": return etag if etag.startswith('"') and etag.endswith('"'): @@ -19,7 +21,7 @@ def quote_etag(etag): def prep_if_match(etag, match_condition): - # type: (str, MatchConditions) -> str + # type: (Optional[str], Optional[MatchConditions]) -> Optional[str] if match_condition == MatchConditions.IfNotModified: if_match = quote_etag(etag) if etag else None return if_match @@ -29,7 +31,7 @@ def prep_if_match(etag, match_condition): def prep_if_none_match(etag, match_condition): - # type: (str, MatchConditions) -> str + # type: (Optional[str], Optional[MatchConditions]) -> Optional[str] if match_condition == MatchConditions.IfModified: if_none_match = quote_etag(etag) if etag else None return if_none_match @@ -39,11 +41,13 @@ def prep_if_none_match(etag, match_condition): def get_endpoint_from_connection_string(connection_string): + # type: (str) -> str endpoint, _, _ = parse_connection_string(connection_string) return endpoint def parse_connection_string(connection_string): + # type: (str) -> Tuple[str, str, str] # connection_string looks like Endpoint=https://xxxxx;Id=xxxxx;Secret=xxxx segments = connection_string.split(";") if len(segments) != 3: @@ -70,4 +74,5 @@ def parse_connection_string(connection_string): def get_current_utc_time(): + # type: () -> str return str(datetime.utcnow().strftime("%b, %d %Y %H:%M:%S.%f ")) + "GMT" diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py index aea69c1c5db5..ef9be559d823 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py @@ -4,7 +4,7 @@ # license information. # ------------------------------------------------------------------------- import binascii -from typing import Dict, Any, Optional +from typing import Dict, Any, Optional, Mapping, Union from requests.structures import CaseInsensitiveDict from azure.core import MatchConditions from azure.core.pipeline import AsyncPipeline @@ -86,8 +86,6 @@ def __init__(self, base_url, credential, **kwargs): base_user_agent=USER_AGENT, **kwargs ) - self._sync_token_policy = None - pipeline = kwargs.get("pipeline") self._sync_token_policy = SyncTokenPolicy() @@ -214,7 +212,7 @@ def list_configuration_settings(self, key_filter=None, label_filter=None, **kwar 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, @@ -239,7 +237,7 @@ async def get_configuration_setting( match_condition=MatchConditions.Unconditionally, **kwargs ): - # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> ConfigurationSetting + # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Union[None, ConfigurationSetting] """Get the matched ConfigurationSetting from Azure App Configuration service @@ -297,7 +295,7 @@ async def get_configuration_setting( @distributed_trace_async async 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. @@ -323,13 +321,13 @@ async def add_configuration_setting(self, configuration_setting, **kwargs): added_config_setting = await async_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 = await 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, @@ -348,7 +346,7 @@ async 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. @@ -381,7 +379,7 @@ async def set_configuration_setting( returned_config_setting = await async_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 @@ -395,7 +393,7 @@ async def set_configuration_setting( try: key_value_set = await 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( @@ -414,7 +412,7 @@ async def set_configuration_setting( @distributed_trace_async async 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 @@ -444,7 +442,7 @@ async def delete_configuration_setting( 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 @@ -463,7 +461,7 @@ async def delete_configuration_setting( 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) @@ -516,7 +514,7 @@ def list_revisions( 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, @@ -535,7 +533,7 @@ def list_revisions( @distributed_trace async 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 diff --git a/sdk/appconfiguration/azure-appconfiguration/mypy.ini b/sdk/appconfiguration/azure-appconfiguration/mypy.ini new file mode 100644 index 000000000000..df95a1584905 --- /dev/null +++ b/sdk/appconfiguration/azure-appconfiguration/mypy.ini @@ -0,0 +1,12 @@ +[mypy] +python_version = 3.6 +warn_unused_configs = True +ignore_missing_imports = True + +# Per-module options: + +[mypy-azure.appconfiguration._generated.*] +ignore_errors = True + +[mypy-azure.core.*] +ignore_errors = True From 9141ba85d110ef075987fba9e772f8d1b92c9df1 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 21 May 2021 12:00:35 -0400 Subject: [PATCH 2/4] new generated --- .../_azure_app_configuration_operations.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/aio/operations/_azure_app_configuration_operations.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/aio/operations/_azure_app_configuration_operations.py index d898efd4c7a3..ee7a0a5b10e2 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/aio/operations/_azure_app_configuration_operations.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_generated/aio/operations/_azure_app_configuration_operations.py @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. From c6f16a2bc8c52e992245ee6ef519dff7ff516671 Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Mon, 24 May 2021 10:36:41 -0400 Subject: [PATCH 3/4] removing optional --- .../_azure_appconfiguration_client.py | 12 ++++++------ .../azure/appconfiguration/_models.py | 4 ++-- .../aio/_azure_configuration_client_async.py | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py index f8fba66a9d12..4ee46f89fe2f 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -4,7 +4,7 @@ # license information. # ------------------------------------------------------------------------- import binascii -from typing import Optional, Any, Mapping +from typing import Optional, Any, Mapping, Union from requests.structures import CaseInsensitiveDict from azure.core import MatchConditions from azure.core.pipeline import Pipeline @@ -226,7 +226,7 @@ def get_configuration_setting( etag="*", match_condition=MatchConditions.Unconditionally, **kwargs - ): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Optional[ConfigurationSetting] + ): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Union[None, ConfigurationSetting] """Get the matched ConfigurationSetting from Azure App Configuration service @@ -283,7 +283,7 @@ def get_configuration_setting( @distributed_trace def add_configuration_setting(self, configuration_setting, **kwargs): - # type: (ConfigurationSetting, **Any) -> Optional[ConfigurationSetting] + # type: (ConfigurationSetting, **Any) -> ConfigurationSetting """Add a ConfigurationSetting instance into the Azure App Configuration service. @@ -332,7 +332,7 @@ def set_configuration_setting( configuration_setting, match_condition=MatchConditions.Unconditionally, **kwargs - ): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> Optional[ConfigurationSetting] + ): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> ConfigurationSetting """Add or update a ConfigurationSetting. If the configuration setting identified by key and label does not exist, this is a create. @@ -396,7 +396,7 @@ def set_configuration_setting( @distributed_trace def delete_configuration_setting(self, key, label=None, **kwargs): - # type: (str, Optional[str], **Any) -> Optional[ConfigurationSetting] + # type: (str, Optional[str], **Any) -> ConfigurationSetting """Delete a ConfigurationSetting if it exists @@ -512,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) -> Optional[ConfigurationSetting] + # type: (ConfigurationSetting, Optional[bool], **Any) -> ConfigurationSetting """Set a configuration setting read only diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py index 44df27866a3c..5616615f8a34 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py @@ -59,7 +59,7 @@ def __init__(self, **kwargs): @classmethod def _from_generated(cls, key_value): - # type: (KeyValue) -> Optional[ConfigurationSetting] + # type: (KeyValue) -> Union[ConfigurationSetting, FeatureFlagConfigurationSetting, SecretReferenceConfigurationSetting] if key_value is None: return key_value if key_value.content_type is not None: @@ -215,7 +215,7 @@ def filters(self, new_filters): @classmethod def _from_generated(cls, key_value): - # type: (KeyValue) -> Optional[Union[FeatureFlagConfigurationSetting, ConfigurationSetting]] + # type: (KeyValue) -> Union[FeatureFlagConfigurationSetting, ConfigurationSetting] try: if key_value is None: return key_value diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py index ef9be559d823..4265d938d11d 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py @@ -295,7 +295,7 @@ async def get_configuration_setting( @distributed_trace_async async def add_configuration_setting(self, configuration_setting, **kwargs): - # type: (ConfigurationSetting, **Any) -> Optional[ConfigurationSetting] + # type: (ConfigurationSetting, **Any) -> ConfigurationSetting """Add a ConfigurationSetting instance into the Azure App Configuration service. @@ -346,7 +346,7 @@ async def set_configuration_setting( configuration_setting, match_condition=MatchConditions.Unconditionally, **kwargs - ): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> Optional[ConfigurationSetting] + ): # type: (ConfigurationSetting, Optional[MatchConditions], **Any) -> ConfigurationSetting """Add or update a ConfigurationSetting. If the configuration setting identified by key and label does not exist, this is a create. @@ -412,7 +412,7 @@ async def set_configuration_setting( @distributed_trace_async async def delete_configuration_setting( self, key, label=None, **kwargs - ): # type: (str, Optional[str], **Any) -> Optional[ConfigurationSetting] + ): # type: (str, Optional[str], **Any) -> ConfigurationSetting """Delete a ConfigurationSetting if it exists @@ -533,7 +533,7 @@ def list_revisions( @distributed_trace async def set_read_only( self, configuration_setting, read_only=True, **kwargs - ): # type: (ConfigurationSetting, Optional[bool], **Any) -> Optional[ConfigurationSetting] + ): # type: (ConfigurationSetting, Optional[bool], **Any) -> ConfigurationSetting """Set a configuration setting read only From d9f4e01953981b0307464c15cbb394ad86f77ecd Mon Sep 17 00:00:00 2001 From: seankane-msft Date: Fri, 28 May 2021 14:56:45 -0400 Subject: [PATCH 4/4] fixes --- .../_azure_appconfiguration_client.py | 12 ++++++------ .../azure/appconfiguration/_models.py | 9 +++++++-- .../aio/_azure_configuration_client_async.py | 13 ++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py index 4ee46f89fe2f..0790fa617a50 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_azure_appconfiguration_client.py @@ -221,12 +221,12 @@ def list_configuration_settings( @distributed_trace def get_configuration_setting( self, - key, - label=None, - etag="*", - match_condition=MatchConditions.Unconditionally, - **kwargs - ): # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Union[None, ConfigurationSetting] + key, # type: str + label=None, # type: Optional[str] + etag="*", # type: Optional[str] + match_condition=MatchConditions.Unconditionally, # type: Optional[MatchConditions] + **kwargs # type: Any + ): # type: (...) -> Union[None, ConfigurationSetting] """Get the matched ConfigurationSetting from Azure App Configuration service diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py index 5616615f8a34..e321400c2ab8 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/_models.py @@ -3,11 +3,16 @@ # Licensed under the MIT License. # ------------------------------------ import json -from typing import Dict, Optional, Any, List, Union, Optional, Mapping +from typing import Dict, Optional, Any, List, Union from msrest.serialization import Model from ._generated.models import KeyValue +PolymorphicConfigurationSetting = Union[ + "ConfigurationSetting", "SecretReferenceConfigurationSetting", "FeatureFlagConfigurationSetting" +] + + class ConfigurationSetting(Model): """A configuration value. Variables are only populated by the server, and will be ignored when @@ -59,7 +64,7 @@ def __init__(self, **kwargs): @classmethod def _from_generated(cls, key_value): - # type: (KeyValue) -> Union[ConfigurationSetting, FeatureFlagConfigurationSetting, SecretReferenceConfigurationSetting] + # type: (KeyValue) -> PolymorphicConfigurationSetting if key_value is None: return key_value if key_value.content_type is not None: diff --git a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py index 4265d938d11d..a90de362a385 100644 --- a/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py +++ b/sdk/appconfiguration/azure-appconfiguration/azure/appconfiguration/aio/_azure_configuration_client_async.py @@ -231,13 +231,12 @@ def list_configuration_settings(self, key_filter=None, label_filter=None, **kwar @distributed_trace_async async def get_configuration_setting( self, - key, - label=None, - etag="*", - match_condition=MatchConditions.Unconditionally, - **kwargs - ): - # type: (str, Optional[str], Optional[str], Optional[MatchConditions], **Any) -> Union[None, ConfigurationSetting] + key: str, + label: Optional[str] = None, + etag: Optional[str] = "*", + match_condition: Optional[MatchConditions] = MatchConditions.Unconditionally, + **kwargs: Any + ) -> Union[None, ConfigurationSetting]: """Get the matched ConfigurationSetting from Azure App Configuration service