Skip to content

feat: add type stubs and marker file for PEP 561 support in google.cloud.storage #1528

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ docs.metadata
# Virtual environment
env/
venv/
.venv/
.env/

# UV generated files
.python-version
uv.lock
hello.py
pyproject.toml

# Test logs
coverage.xml
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ global-exclude __pycache__

# Exclude scripts for samples readmegen
prune scripts/readme-gen

include google/cloud/storage/py.typed
104 changes: 104 additions & 0 deletions google/cloud/storage/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Stubs for google.cloud.storage package
# Generated minimal PEP 561 stub to improve Pylance/Pyright experience.
from __future__ import annotations

from typing import Any, Optional, MutableMapping, Sequence, Tuple

__all__ = ["__version__", "Batch", "Blob", "Bucket", "Client"]

__version__: str

class Batch:
def __init__(self, client: "Client", raise_exception: bool = True) -> None: ...

def finish(self, raise_exception: bool = True) -> Sequence[Tuple[Any, Any]]: ...


class Blob:
STORAGE_CLASSES: Sequence[str]

def __init__(
self,
name: str,
bucket: "Bucket",
chunk_size: Optional[int] = None,
encryption_key: Optional[bytes] = None,
kms_key_name: Optional[str] = None,
generation: Optional[int] = None,
) -> None: ...

name: str
bucket: "Bucket"
generation: Optional[int]

@property
def public_url(self) -> str: ...

@property
def client(self) -> "Client": ...

def from_uri(self, uri: str) -> "Blob": ...

def download_as_bytes(self, timeout: Optional[float] = ...) -> bytes: ...

def upload_from_file(self, file_obj: Any, timeout: Optional[float] = ...) -> None: ...


class Bucket:
STORAGE_CLASSES: Sequence[str]

def __init__(
self,
client: "Client",
name: str,
user_project: Optional[str] = None,
generation: Optional[int] = None,
) -> None: ...

name: str
client: "Client"
user_project: Optional[str]

def blob(self, blob_name: str, chunk_size: Optional[int] = None) -> Blob: ...

def get_blob(self, blob_name: str, timeout: Optional[float] = ...) -> Optional[Blob]: ...

def create(self, timeout: Optional[float] = ...) -> None: ...

@classmethod
def from_string(cls, uri: str, client: Optional["Client"] = ...) -> "Bucket": ...


class Client:
SCOPE: Sequence[str]

def __init__(
self,
project: Optional[str] = ...,
credentials: Optional[Any] = ...,
_http: Optional[Any] = ...,
client_info: Optional[Any] = ...,
client_options: Optional[Any] = ...,
use_auth_w_custom_endpoint: bool = True,
extra_headers: Optional[MutableMapping[str, str]] = ..., *, api_key: Optional[str] = ...,
) -> None: ...

project: Optional[str]

@classmethod
def create_anonymous_client(cls) -> "Client": ...

@property
def universe_domain(self) -> str: ...

@property
def api_endpoint(self) -> str: ...

@property
def current_batch(self) -> Optional[Batch]: ...

def bucket(self, bucket_name: str, user_project: Optional[str] = None, generation: Optional[int] = None) -> Bucket: ...

def batch(self, raise_exception: bool = True) -> Batch: ...

def get_service_account_email(self, project: Optional[str] = None, timeout: Optional[float] = ..., retry: Optional[Any] = ...) -> str: ...
1 change: 1 addition & 0 deletions google/cloud/storage/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Marker file for PEP 561
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
],
platforms="Posix; MacOS X; Windows",
packages=packages,
package_data={
"google.cloud.storage": ["py.typed"],
},
install_requires=dependencies,
extras_require=extras,
python_requires=">=3.7",
Expand Down
Loading