From 591adf9c5e8bd0adbbd1ed21a01eb73a9d05f3f5 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 27 Sep 2019 10:04:55 -0400 Subject: [PATCH 1/3] docs(storage): clarify docstring for 'Blob.download_as_string' Specify that the returned value is bytes in the summary, and note the historical reason for the confused method name. Closes #9290. --- storage/google/cloud/storage/blob.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index ded2793db87d..ce11905c807e 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -712,7 +712,11 @@ def download_to_filename(self, filename, client=None, start=None, end=None): os.utime(file_obj.name, (mtime, mtime)) def download_as_string(self, client=None, start=None, end=None): - """Download the contents of this blob as a string. + """Download the contents of this blob as a bytes object. + + .. note:: + the method name, ``download_as_string`` was chosen for + compatibility with the ``boto`` library's API. If :attr:`user_project` is set on the bucket, bills the API request to that project. From 1a54003ab3000e85f1630b50d8eadc6f090b0808 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 27 Sep 2019 11:26:11 -0400 Subject: [PATCH 2/3] Drop reference to 'boto'. --- storage/google/cloud/storage/blob.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index ce11905c807e..5c74931a4e56 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -714,10 +714,6 @@ def download_to_filename(self, filename, client=None, start=None, end=None): def download_as_string(self, client=None, start=None, end=None): """Download the contents of this blob as a bytes object. - .. note:: - the method name, ``download_as_string`` was chosen for - compatibility with the ``boto`` library's API. - If :attr:`user_project` is set on the bucket, bills the API request to that project. From 892d1f9e448eb878c589d70396dc13a3b4d7084c Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 27 Sep 2019 11:26:40 -0400 Subject: [PATCH 3/3] Use explicit bytes literal for clarity. --- storage/docs/snippets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/docs/snippets.py b/storage/docs/snippets.py index ed16c5279e30..8171d5cf80f1 100644 --- a/storage/docs/snippets.py +++ b/storage/docs/snippets.py @@ -39,7 +39,7 @@ def storage_get_started(client, to_delete): bucket = client.get_bucket("bucket-id-here") # Then do other things... blob = bucket.get_blob("/remote/path/to/file.txt") - assert blob.download_as_string() == "My old contents!" + assert blob.download_as_string() == b"My old contents!" blob.upload_from_string("New contents!") blob2 = bucket.blob("/remote/path/storage.txt") blob2.upload_from_filename(filename="/local/path.txt")