1818Note: google-cloud-storage is synchronous. All operations are wrapped in
1919asyncio.to_thread to avoid blocking the event loop.
2020"""
21+
2122from __future__ import annotations
2223
2324import asyncio
@@ -50,13 +51,13 @@ def _get_client(self) -> GCSClient:
5051 if self .client is not None :
5152 return self .client
5253 try :
53- from google .cloud import storage # type: ignore[import-untyped]
54+ from google .cloud import storage
5455 except ImportError as exc :
5556 raise ImportError (
5657 "GCSStorage requires google-cloud-storage. "
5758 "Install with: pip install 'jqueue[gcs]'"
5859 ) from exc
59- return storage .Client () # type: ignore[return-value]
60+ return storage .Client ()
6061
6162 async def read (self ) -> tuple [bytes , str | None ]:
6263 """Read the state blob. Returns (b"", None) if the blob does not exist."""
@@ -86,15 +87,15 @@ async def write(
8687
8788 def _sync_read (self ) -> tuple [bytes , str | None ]:
8889 try :
89- from google .api_core import exceptions as gapi_exc # type: ignore[import-untyped]
90+ from google .api_core import exceptions as gapi_exc
9091 except ImportError as exc :
9192 raise ImportError (
9293 "GCSStorage requires google-cloud-storage. "
9394 "Install with: pip install 'jqueue[gcs]'"
9495 ) from exc
9596
9697 client = self ._get_client ()
97- blob = client .bucket (self .bucket_name ).blob (self .blob_name ) # type: ignore[attr-defined]
98+ blob = client .bucket (self .bucket_name ).blob (self .blob_name )
9899 try :
99100 content : bytes = blob .download_as_bytes ()
100101 return content , str (blob .generation )
@@ -103,27 +104,27 @@ def _sync_read(self) -> tuple[bytes, str | None]:
103104
104105 def _sync_write (self , content : bytes , if_match : str | None ) -> str :
105106 try :
106- from google .api_core import exceptions as gapi_exc # type: ignore[import-untyped]
107+ from google .api_core import exceptions as gapi_exc
107108 except ImportError as exc :
108109 raise ImportError (
109110 "GCSStorage requires google-cloud-storage. "
110111 "Install with: pip install 'jqueue[gcs]'"
111112 ) from exc
112113
113114 client = self ._get_client ()
114- blob = client .bucket (self .bucket_name ).blob (self .blob_name ) # type: ignore[attr-defined]
115+ blob = client .bucket (self .bucket_name ).blob (self .blob_name )
115116
116117 # if_generation_match=0 → "blob must not exist yet"
117118 gen_match : int = 0 if if_match is None else int (if_match )
118119
119120 try :
120- blob .upload_from_string ( # type: ignore[attr-defined]
121+ blob .upload_from_string (
121122 content ,
122123 content_type = "application/json" ,
123124 if_generation_match = gen_match ,
124125 )
125126 except gapi_exc .PreconditionFailed as exc :
126127 raise CASConflictError ("GCS generation mismatch" ) from exc
127128
128- blob .reload () # type: ignore[attr-defined]
129+ blob .reload ()
129130 return str (blob .generation )
0 commit comments