-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Typing errors in blob storage documentation code #24661
Comments
Thanks for reaching out @TobiRoby! We'll investigate and get back to you asap. |
Thank you for your feedback. This has been routed to the support team for assistance. |
I think this is a mypy bug, specifically python/mypy#3644 I reckon it can be worked around by changing the type so that instead of
it goes
|
Hi @TobiRoby, for your second error with open(download_file_path, "wb") as download_file:
content: bytes = blob_client.download_blob().readall()
download_file.write(content) For the first error @annatisch Anna, curious what you think about adjusting the type for |
@jalauzon-msft the advice you are offering should be applied to your own code: this isn't the user's code it is
Edit: or, perhaps you could get more sophisticated with the annotations, I think you should be able to Then users wouldn't have to jump through such hoops. |
One more thought, perhaps the most important one really: wouldn't it be nice if the workflows for this repository checked the type annotations, so that such things were caught before they were shipped? |
Thanks for your feedback.
with open(download_file_path, "wb") as download_file:
content: bytes = blob_client.download_blob().readall()
download_file.write(content) @jalauzon-msft can you add it to the official documentation, please?
|
I really like your suggestion. |
Hi @dimbleby and @TobiRoby, thanks for the follow-ups! Sorry, I totally missed this was coming from our documented sample so that's "egg on my face". We can consider updating the sample, but I think it would be better to fix the typing as David mentioned. It's just a bit tricky and likely For the other issue, seeing how that MyPy bug has existed for some time, we can make the change David suggested (or something similar) assuming that will work. And a note on a type checking workflow. We will be working on that sometime in the near future. This repository already supports MyPy type checking with our internal pipelines, we just need to get Storage included in the checks. |
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage. Issue DetailsHi, I am receiving typing errors from 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 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
|
Both of the type issues have been fixed in |
Is there an estimated release date for 12.14.0? |
Hi @eladkal, we are planning a preview release for 12.14.0b1 early this month (ideally next week) and a full release of 12.14.0 in early September. If you need a solution faster, please share an example of your typing error and possibly we can come up with a workaround. |
@jalauzon-msft failure is:
|
@eladkal, thanks. I can confirm this should be addresed in with open(file_path, "wb") as fileblob:
stream = self.download(container_name=container_name, blob_name=blob_name, **kwargs)
content: bytes = stream.readall()
fileblob.write(content) Hopefully this can resolve this issue for you prior to us releasing the fix. Thanks. |
Tried that.. it didn't work. We will release next azure provider for Airflow with old versions. Once 12.14.0 is released we will adjust accordingly. |
@jalauzon-msft Is there estimation for the release? |
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. |
Hi,
I am receiving typing errors from
mypy
when following theblob 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):
I receive 2 errors when applying
mypy
:environment
python: 3.10.4
azure-storage-blob: 12.12.0
mypy: 0.960
The text was updated successfully, but these errors were encountered: