Skip to content

azure-storage-blob BlobClient.upload_blob mistyped argument #23362

Description

@jayqi
  • Package Name: azure-storage-blob
  • Package Version: 12.9.0

Describe the bug

azure.storage.blob.BlobClient.upload_blob and the method that it wraps BlobClient._upload_blob_options both have the type annotation Union[Iterable[AnyStr], IO[AnyStr]] for the data argument.

def upload_blob( # pylint: disable=too-many-locals
self, data, # type: Union[Iterable[AnyStr], IO[AnyStr]]
blob_type=BlobType.BlockBlob, # type: Union[str, BlobType]
length=None, # type: Optional[int]
metadata=None, # type: Optional[Dict[str, str]]
**kwargs
):

def _upload_blob_options( # pylint:disable=too-many-statements
self, data, # type: Union[Iterable[AnyStr], IO[AnyStr]]
blob_type=BlobType.BlockBlob, # type: Union[str, BlobType]
length=None, # type: Optional[int]
metadata=None, # type: Optional[Dict[str, str]]
**kwargs
):

However, these methods also support cases where data is str or bytes.

This bit handles the case where data is str:

if isinstance(data, six.text_type):
data = data.encode(encoding) # type: ignore

and this bit handles the case where data is bytes:

if isinstance(data, bytes):
stream = BytesIO(data)

Expected behavior

The current annotation should be Union[AnyStr, Iterable[AnyStr], IO[AnyStr]].

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions