From aa44b0232908895506ecda8b6539213e14d9b0c3 Mon Sep 17 00:00:00 2001 From: Yalin Li Date: Wed, 8 Sep 2021 15:17:39 -0700 Subject: [PATCH] Run mypy in azure-keyvault-secrets CI (#20507) --- eng/tox/mypy_hard_failure_packages.py | 1 + .../azure/keyvault/keys/_shared/_polling.py | 4 +- .../azure/keyvault/secrets/_client.py | 5 +- .../azure/keyvault/secrets/_models.py | 111 +++++++++--------- .../keyvault/secrets/_shared/_polling.py | 4 +- sdk/keyvault/azure-keyvault-secrets/mypy.ini | 7 ++ 6 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 sdk/keyvault/azure-keyvault-secrets/mypy.ini diff --git a/eng/tox/mypy_hard_failure_packages.py b/eng/tox/mypy_hard_failure_packages.py index 7619732b13b4..3ae063eb4fb1 100644 --- a/eng/tox/mypy_hard_failure_packages.py +++ b/eng/tox/mypy_hard_failure_packages.py @@ -11,6 +11,7 @@ "azure-identity", "azure-keyvault-administration", "azure-keyvault-certificates", + "azure-keyvault-secrets", "azure-servicebus", "azure-ai-textanalytics", "azure-ai-formrecognizer", diff --git a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/_polling.py b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/_polling.py index df63ad0a70ec..ec1898453d81 100644 --- a/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/_polling.py +++ b/sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_shared/_polling.py @@ -33,11 +33,11 @@ class KeyVaultOperationPoller(LROPoller): # pylint: disable=arguments-differ def __init__(self, polling_method): # type: (PollingMethod) -> None - super(KeyVaultOperationPoller, self).__init__(None, None, None, NoPolling()) + super(KeyVaultOperationPoller, self).__init__(None, None, lambda *_: None, NoPolling()) self._polling_method = polling_method # pylint: disable=arguments-differ - def result(self): + def result(self): # type: ignore # type: () -> Any """Returns a representation of the final resource without waiting for the operation to complete. diff --git a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_client.py b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_client.py index 2f1e376504e8..ed3790c0a715 100644 --- a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_client.py +++ b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_client.py @@ -4,6 +4,7 @@ # ------------------------------------ from functools import partial from azure.core.tracing.decorator import distributed_trace +from azure.core.polling import LROPoller from ._models import KeyVaultSecret, DeletedSecret, SecretProperties from ._shared import KeyVaultClientBase @@ -294,7 +295,7 @@ def restore_secret_backup(self, backup, **kwargs): @distributed_trace def begin_delete_secret(self, name, **kwargs): - # type: (str, **Any) -> DeletedSecret + # type: (str, **Any) -> LROPoller """Delete all versions of a secret. Requires secrets/delete permission. When this method returns Key Vault has begun deleting the secret. Deletion may take several seconds in a vault @@ -416,7 +417,7 @@ def purge_deleted_secret(self, name, **kwargs): @distributed_trace def begin_recover_deleted_secret(self, name, **kwargs): - # type: (str, **Any) -> SecretProperties + # type: (str, **Any) -> LROPoller """Recover a deleted secret to its latest version. Possible only in a vault with soft-delete enabled. If the vault does not have soft-delete enabled, :func:`begin_delete_secret` is permanent, and this method will diff --git a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_models.py b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_models.py index 03ef5dc268b8..7cb02cef9a3f 100644 --- a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_models.py +++ b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_models.py @@ -20,10 +20,10 @@ class SecretProperties(object): """A secret's id and attributes.""" def __init__(self, attributes, vault_id, **kwargs): - # type: (_models.SecretAttributes, str, **Any) -> None + # type: (Optional[_models.SecretAttributes], Optional[str], **Any) -> None self._attributes = attributes self._id = vault_id - self._vault_id = KeyVaultSecretIdentifier(vault_id) + self._vault_id = KeyVaultSecretIdentifier(vault_id) if vault_id else None self._content_type = kwargs.get("content_type", None) self._key_id = kwargs.get("key_id", None) self._managed = kwargs.get("managed", None) @@ -60,82 +60,82 @@ def _from_secret_item(cls, secret_item): @property def content_type(self): - # type: () -> str + # type: () -> Optional[str] """An arbitrary string indicating the type of the secret - :rtype: str + :rtype: str or None """ return self._content_type @property def id(self): - # type: () -> str + # type: () -> Optional[str] """The secret's id - :rtype: str + :rtype: str or None """ return self._id @property def key_id(self): - # type: () -> str + # type: () -> Optional[str] """If this secret backs a certificate, this property is the identifier of the corresponding key. - :rtype: str + :rtype: str or None """ return self._key_id @property def enabled(self): - # type: () -> bool + # type: () -> Optional[bool] """Whether the secret is enabled for use - :rtype: bool + :rtype: bool or None """ - return self._attributes.enabled + return self._attributes.enabled if self._attributes else None @property def not_before(self): - # type: () -> datetime + # type: () -> Optional[datetime] """The time before which the secret can not be used, in UTC - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ - return self._attributes.not_before + return self._attributes.not_before if self._attributes else None @property def expires_on(self): - # type: () -> datetime + # type: () -> Optional[datetime] """When the secret expires, in UTC - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ - return self._attributes.expires + return self._attributes.expires if self._attributes else None @property def created_on(self): - # type: () -> datetime + # type: () -> Optional[datetime] """When the secret was created, in UTC - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ - return self._attributes.created + return self._attributes.created if self._attributes else None @property def updated_on(self): - # type: () -> datetime + # type: () -> Optional[datetime] """When the secret was last updated, in UTC - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ - return self._attributes.updated + return self._attributes.updated if self._attributes else None @property def recoverable_days(self): # type: () -> Optional[int] """The number of days the key is retained before being deleted from a soft-delete enabled Key Vault. - :rtype: int + :rtype: int or None """ # recoverable_days was added in 7.1-preview if self._attributes and hasattr(self._attributes, "recoverable_days"): @@ -144,46 +144,47 @@ def recoverable_days(self): @property def recovery_level(self): - # type: () -> str + # type: () -> Optional[str] """The vault's deletion recovery level for secrets - :rtype: str + :rtype: str or None """ - return self._attributes.recovery_level + return self._attributes.recovery_level if self._attributes else None @property def vault_url(self): - # type: () -> str + # type: () -> Optional[str] """URL of the vault containing the secret - :rtype: str + :rtype: str or None """ - return self._vault_id.vault_url + return self._vault_id.vault_url if self._vault_id else None @property def name(self): - # type: () -> str + # type: () -> Optional[str] """The secret's name - :rtype: str + :rtype: str or None """ - return self._vault_id.name + return self._vault_id.name if self._vault_id else None @property def version(self): - # type: () -> str + # type: () -> Optional[str] """The secret's version - :rtype: str + :rtype: str or None """ - return self._vault_id.version + return self._vault_id.version if self._vault_id else None @property def tags(self): - # type: () -> Dict[str, str] + # type: () -> Optional[Dict[str, str]] """Application specific metadata in the form of key-value pairs - :rtype: dict""" + :rtype: dict or None + """ return self._tags @@ -191,7 +192,7 @@ class KeyVaultSecret(object): """All of a secret's properties, and its value.""" def __init__(self, properties, value): - # type: (SecretProperties, str) -> None + # type: (SecretProperties, Optional[str]) -> None self._properties = properties self._value = value @@ -210,19 +211,19 @@ def _from_secret_bundle(cls, secret_bundle): @property def name(self): - # type: () -> str + # type: () -> Optional[str] """The secret's name - :rtype: str + :rtype: str or None """ return self._properties.name @property def id(self): - # type: () -> str + # type: () -> Optional[str] """The secret's id - :rtype: str + :rtype: str or None """ return self._properties.id @@ -237,10 +238,10 @@ def properties(self): @property def value(self): - # type: () -> str + # type: () -> Optional[str] """The secret's value - :rtype: str + :rtype: str or None """ return self._value @@ -329,19 +330,19 @@ def _from_deleted_secret_item(cls, deleted_secret_item): @property def name(self): - # type: () -> str + # type: () -> Optional[str] """The secret's name - :rtype: str + :rtype: str or None """ return self._properties.name @property def id(self): - # type: () -> str + # type: () -> Optional[str] """The secret's id - :rtype: str + :rtype: str or None """ return self._properties.id @@ -356,27 +357,27 @@ def properties(self): @property def deleted_date(self): - # type: () -> datetime + # type: () -> Optional[datetime] """When the secret was deleted, in UTC - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ return self._deleted_date @property def recovery_id(self): - # type: () -> str + # type: () -> Optional[str] """An identifier used to recover the deleted secret. Returns ``None`` if soft-delete is disabled. - :rtype: str + :rtype: str or None """ return self._recovery_id @property def scheduled_purge_date(self): - # type: () -> datetime + # type: () -> Optional[datetime] """When the secret is scheduled to be purged, in UTC. Returns ``None`` if soft-delete is disabled. - :rtype: ~datetime.datetime + :rtype: ~datetime.datetime or None """ return self._scheduled_purge_date diff --git a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/_polling.py b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/_polling.py index df63ad0a70ec..ec1898453d81 100644 --- a/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/_polling.py +++ b/sdk/keyvault/azure-keyvault-secrets/azure/keyvault/secrets/_shared/_polling.py @@ -33,11 +33,11 @@ class KeyVaultOperationPoller(LROPoller): # pylint: disable=arguments-differ def __init__(self, polling_method): # type: (PollingMethod) -> None - super(KeyVaultOperationPoller, self).__init__(None, None, None, NoPolling()) + super(KeyVaultOperationPoller, self).__init__(None, None, lambda *_: None, NoPolling()) self._polling_method = polling_method # pylint: disable=arguments-differ - def result(self): + def result(self): # type: ignore # type: () -> Any """Returns a representation of the final resource without waiting for the operation to complete. diff --git a/sdk/keyvault/azure-keyvault-secrets/mypy.ini b/sdk/keyvault/azure-keyvault-secrets/mypy.ini new file mode 100644 index 000000000000..18b37b44c426 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-secrets/mypy.ini @@ -0,0 +1,7 @@ +[mypy] +python_version = 3.6 +warn_unused_configs = True +ignore_missing_imports = True + +[mypy-azure.keyvault.*._generated.*] +ignore_errors = True