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

[Storage] Adjust type hints for __init__ and classmethods in file-share, queue, and changefeed #26743

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
# license information.
# --------------------------------------------------------------------------
# pylint: disable=too-many-lines,no-self-use
from typing import ( # pylint: disable=unused-import
Optional, Any, TYPE_CHECKING, Dict
from typing import (
Any, Dict, Optional, Union,
TYPE_CHECKING
)

from azure.core.paging import ItemPaged
from azure.storage.blob import BlobServiceClient # pylint: disable=no-name-in-module

from azure.storage.blob._shared.base_client import parse_connection_str
from ._models import ChangeFeedPaged

if TYPE_CHECKING:
from datetime import datetime
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential


class ChangeFeedClient(object): # pylint: disable=too-many-public-methods
class ChangeFeedClient(object):
"""A client to interact with a specific account change feed.

:param str account_url:
Expand Down Expand Up @@ -52,19 +53,18 @@ class ChangeFeedClient(object): # pylint: disable=too-many-public-methods
:caption: Creating the ChangeFeedClient from a URL to a public blob (no auth needed).
"""
def __init__(
self, account_url, # type: str
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> None
self, account_url: str,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> None:
self._blob_service_client = BlobServiceClient(account_url, credential, **kwargs)

@classmethod
def from_connection_string(
cls, conn_str, # type: str
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
): # type: (...) -> ChangeFeedClient
cls, conn_str: str,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> "ChangeFeedClient":
"""Create ChangeFeedClient from a Connection String.

:param str conn_str:
Expand Down Expand Up @@ -95,8 +95,7 @@ def from_connection_string(
kwargs['secondary_hostname'] = secondary
return cls(account_url, credential=credential, **kwargs)

def list_changes(self, **kwargs):
# type: (**Any) -> ItemPaged[Dict]
def list_changes(self, **kwargs: Any) -> ItemPaged[Dict]:
"""Returns a generator to list the change feed events.
The generator will lazily follow the continuation tokens returned by
the service.
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-file-share/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

### Other Changes
- Added `typing-extensions>=4.0.1` as a dependency.

## 12.10.0 (2022-10-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@

import functools
import time
from typing import ( # pylint: disable=unused-import
from typing import (
Optional, Union, Any, Dict, TYPE_CHECKING
)


try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore
from urllib.parse import urlparse, quote, unquote

import six
from typing_extensions import Self

from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
from azure.core.paging import ItemPaged
from azure.core.pipeline import Pipeline
from azure.core.tracing.decorator import distributed_trace

from ._generated import AzureFileStorage
from ._shared.base_client import StorageAccountHostsMixin, TransportWrapper, parse_connection_str, parse_query
from ._shared.request_handlers import add_metadata_headers
Expand All @@ -35,8 +30,9 @@
from ._models import DirectoryPropertiesPaged, HandlesPaged, NTFSAttributes # pylint: disable=unused-import

if TYPE_CHECKING:
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential
from datetime import datetime
from ._models import ShareProperties, DirectoryProperties, ContentSettings
from ._models import DirectoryProperties
from ._generated.models import HandleItem


Expand Down Expand Up @@ -81,15 +77,14 @@ class ShareDirectoryClient(StorageAccountHostsMixin):
The hostname of the secondary endpoint.
:keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024.
"""
def __init__( # type: ignore
self, account_url, # type: str
share_name, # type: str
directory_path, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Optional[Any]
):
# type: (...) -> None
def __init__(
self, account_url: str,
share_name: str,
directory_path: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> None:
try:
if not account_url.lower().startswith('http'):
account_url = "https://" + account_url
Expand Down Expand Up @@ -125,12 +120,12 @@ def __init__( # type: ignore
self._client._config.version = get_api_version(kwargs) # pylint: disable=protected-access

@classmethod
def from_directory_url(cls, directory_url, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Optional[Any]
):
# type: (...) -> ShareDirectoryClient
def from_directory_url(
cls, directory_url: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""Create a ShareDirectoryClient from a directory url.

:param str directory_url:
Expand Down Expand Up @@ -190,13 +185,12 @@ def _format_url(self, hostname):

@classmethod
def from_connection_string(
cls, conn_str, # type: str
share_name, # type: str
directory_path, # type: str
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> ShareDirectoryClient
cls, conn_str: str,
share_name: str,
directory_path: str,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""Create ShareDirectoryClient from a Connection String.

:param str conn_str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
import functools
import time
from io import BytesIO
from typing import ( # pylint: disable=unused-import
Optional, Union, IO, List, Dict, Any, Iterable, Tuple,
from typing import (
Optional, Union, List, Dict, Any, Tuple,
TYPE_CHECKING
)


try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore
from urllib.parse import urlparse, quote, unquote

import six
from typing_extensions import Self

from azure.core.exceptions import HttpResponseError
from azure.core.paging import ItemPaged # pylint: disable=ungrouped-imports
from azure.core.tracing.decorator import distributed_trace

from ._generated import AzureFileStorage
from ._generated.models import FileHTTPHeaders
from ._shared.uploads import IterStreamer, FileChunkUploader, upload_data_chunks
Expand All @@ -46,8 +41,9 @@
from ._download import StorageStreamDownloader

if TYPE_CHECKING:
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential
from datetime import datetime
from ._models import ShareProperties, ContentSettings, FileProperties, Handle
from ._models import ContentSettings, FileProperties, Handle
from ._generated.models import HandleItem


Expand Down Expand Up @@ -141,15 +137,14 @@ class ShareFileClient(StorageAccountHostsMixin):
The hostname of the secondary endpoint.
:keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024.
"""
def __init__( # type: ignore
self, account_url, # type: str
share_name, # type: str
file_path, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> None
def __init__(
self, account_url: str,
share_name: str,
file_path: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> None:
try:
if not account_url.lower().startswith('http'):
account_url = "https://" + account_url
Expand Down Expand Up @@ -189,12 +184,11 @@ def __init__( # type: ignore

@classmethod
def from_file_url(
cls, file_url, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> ShareFileClient
cls, file_url: str, # type: str
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""A client to interact with a specific file, although that file may not yet exist.

:param str file_url: The full URI to the file.
Expand Down Expand Up @@ -247,14 +241,13 @@ def _format_url(self, hostname):

@classmethod
def from_connection_string(
cls, conn_str, # type: str
share_name, # type: str
file_path, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> ShareFileClient
cls, conn_str: str,
share_name: str,
file_path: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""Create ShareFileClient from a Connection String.

:param str conn_str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
# license information.
# --------------------------------------------------------------------------

from typing import ( # pylint: disable=unused-import
from typing import (
Optional, Union, Dict, Any, Iterable, TYPE_CHECKING
)


try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore
from urllib.parse import urlparse, quote, unquote

import six
from typing_extensions import Self

from azure.core.exceptions import HttpResponseError
from azure.core.tracing.decorator import distributed_trace
from azure.core.pipeline import Pipeline
Expand All @@ -39,6 +35,7 @@


if TYPE_CHECKING:
from azure.core.credentials import AzureNamedKeyCredential, AzureSasCredential, TokenCredential
from ._models import ShareProperties, AccessPolicy


Expand Down Expand Up @@ -80,14 +77,13 @@ class ShareClient(StorageAccountHostsMixin): # pylint: disable=too-many-public-m
The hostname of the secondary endpoint.
:keyword int max_range_size: The maximum range size used for a file upload. Defaults to 4*1024*1024.
"""
def __init__( # type: ignore
self, account_url, # type: str
share_name, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> None
def __init__(
self, account_url: str,
share_name: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> None:
try:
if not account_url.lower().startswith('http'):
account_url = "https://" + account_url
Expand Down Expand Up @@ -122,12 +118,12 @@ def __init__( # type: ignore
self._client._config.version = get_api_version(kwargs) # pylint: disable=protected-access

@classmethod
def from_share_url(cls, share_url, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> ShareClient
def from_share_url(
cls, share_url: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""
:param str share_url: The full URI to the share.
:param str snapshot:
Expand Down Expand Up @@ -194,13 +190,12 @@ def _format_url(self, hostname):

@classmethod
def from_connection_string(
cls, conn_str, # type: str
share_name, # type: str
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long
**kwargs # type: Any
):
# type: (...) -> ShareClient
cls, conn_str: str,
share_name: str,
snapshot: Optional[Union[str, Dict[str, Any]]] = None,
credential: Optional[Union[str, Dict[str, str], "AzureNamedKeyCredential", "AzureSasCredential", "TokenCredential"]] = None, # pylint: disable=line-too-long
**kwargs: Any
) -> Self:
"""Create ShareClient from a Connection String.

:param str conn_str:
Expand Down
Loading