question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typing errors in blob storage documentation code

See original GitHub issue

Hi,

I am receiving typing errors from mypy when following the blob storage examples in the official documentation.

It would be awesome, if the documentation can provide an example with no type errors 😃

This is the code I am type checking (copy & pasted from the linked documentation):

import os
import uuid

from azure.storage.blob import BlobServiceClient

# Create the BlobServiceClient object which will be used to create a container client
blob_service_client: BlobServiceClient = BlobServiceClient.from_connection_string(
    "connect_str"
)
# Create a unique name for the container
container_name = str(uuid.uuid4())

# Create a local directory to hold blob data
local_path = "./data"
os.mkdir(local_path)

# Create a file in the local data directory to upload and download
local_file_name = str(uuid.uuid4()) + ".txt"
upload_file_path = os.path.join(local_path, local_file_name)

# Write text to the file
file = open(upload_file_path, "w")
file.write("Hello, World!")
file.close()

# Create a blob client using the local file name as the name for the blob
blob_client = blob_service_client.get_blob_client(
    container=container_name, blob=local_file_name
)

print("\nUploading to Azure Storage as blob:\n\t" + local_file_name)

# Upload the created file
with open(upload_file_path, "rb") as data:
    blob_client.upload_blob(data)

download_file_path = os.path.join(
    local_path, str.replace(local_file_name, ".txt", "DOWNLOAD.txt")
)
print("\nDownloading blob to \n\t" + download_file_path)

with open(download_file_path, "wb") as download_file:
    download_file.write(blob_client.download_blob().readall())

I receive 2 errors when applying mypy:

test.py:35: error: Argument 1 to "upload_blob" of "BlobClient" has incompatible type "BufferedReader"; expected "Iterable[str]"
test.py:35: note: Following member(s) of "BufferedReader" have conflicts:
test.py:35: note:     Expected:
test.py:35: note:         def __iter__(self) -> Iterator[str]
test.py:35: note:     Got:
test.py:35: note:         def __iter__(self) -> Iterator[bytes]
test.py:43: error: Argument 1 to "write" of "BufferedWriter" has incompatible type "Union[bytes, str]"; expected "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]"
Found 2 errors in 1 file (checked 1 source file)

environment python: 3.10.4 azure-storage-blob: 12.12.0 mypy: 0.960

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eladkalcommented, Aug 3, 2022

Is there an estimated release date for 12.14.0? Apache Airflow uses azure-storage-blob for the Azure provider and currently we are unable to update package version due to the typing problem. It seems like you already fixed it but have not yet release.

https://github.com/apache/airflow/pull/25426

0reactions
jalauzon-msftcommented, Oct 5, 2022

Hi @eladkal, the plan is for this to release as part of 12.14.0 that is tentatively scheduled for some time next week. We were hoping to have this released sooner but ran into some issues that pushed our release schedule by about a month.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Blob Storage error codes - Microsoft Learn
Error code HTTP status code User message BlobAlreadyExists Conflict (409) The specified blob already exists. BlobNotFound Not Found (404) The specified blob does not exist. ContainerAlreadyExists...
Read more >
Troubleshoot Azure Blob Storage Log Collection
Error while deploying the ARM template​ · Go to the resource group where the deployment failed · Click on Failed deployment, and then...
Read more >
@azure/storage-blob - npm
Blob storage is designed for: Serving images or documents directly to a browser. Storing files for distributed access. Streaming video and audio ...
Read more >
rest - "404 Resource Not Found" From Azure Blob Storage ...
Then set the Access type to either Blob or Container if you want to allow listing of the container. Microsoft seems to have...
Read more >
Upload files with Cloud Storage on Web - Firebase
Upload from a Blob or File; Upload from a Byte Array; Upload from a String. Add File Metadata; Manage Uploads; Monitor Upload Progress;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found