googleapis / googleapis/google-cloud-python

Missing type annotations (py.typed/stubs) for google.cloud.storage causing Pylance/Pyright complaints

Abierto
#15,969 3 comentarios 8 reacciones 1 asignado Reclamado por @chandra-siri Ver en GitHub
api: storage
Lenguaje dominante
Python
Estrellas
5.4k
Forks
1.8k
Merge medio
3 d 4 h
PR fusionados (30 d)
122

Descripción

#### Summary

Using `google-cloud-storage` in Python results in incomplete or missing type information, which triggers `reportMissingTypeStubs` and `reportUnknownMemberType` errors in Pylance and Pyright. This degrades editor support (e.g., autocompletion, type safety) and creates noise during development.

#### Steps to Reproduce

1. Create a virtual environment and install dependencies:

```bash
python -m venv venv
source venv/bin/activate
pip install google-cloud-storage pyright
```
2. Create a simple script:

```python
from google.cloud.storage import Blob

blob = Blob(name="test", bucket="my-bucket")
print(blob.name)
```
3. Enable strict type checking:

```toml
[tool.pyright]
reportMissingTypeStubs = true
typeCheckingMode = "strict"
```
4. Run Pyright or let Pylance analyze:

```bash
pyright example.py
```
5. Errors:

```
error: Stub file not found for "google.cloud.storage" (reportMissingTypeStubs)
error: Type of "name" is partially unknown (reportUnknownMemberType)
```

#### Expected Behavior

* A `py.typed` file in `google.cloud.storage` or
* An official type stub file (`google.cloud.storage.pyi`) with correct annotations
* This would resolve type-checking errors and support proper IntelliSense.

#### Workarounds Tryed

* There's no embedded type information or `py.typed` marker in the installed library.
* Community type stubs don’t currently exist for this package.
* Pyright/Pylance treat this as “as-designed” and suggest suppressing diagnostics rather than improving type support ([GitHub][1]).

#### Proposal

* **Add a minimal `py.typed`** to `google-cloud-storage` to signal typedness.
* **Provide a corresponding `.pyi` stub** (e.g., in typeshed or library package) covering common methods like:

```python
class Blob:
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
# etc.
```
* Alternatively, **publish stubs in typeshed**, or coordinate with that project.

#### Benefits

* Enable better developer experience (autocomplete, inline docs, accurate type errors).
* Reduce friction during code editing and static analysis.
* Attract contributions from type-aware users.

#### Additional Context

* Pyright correctly labels this as a missing type stubs issue and marks it “as‑designed.” ([GitHub][1])
* This has also affected other `google.cloud` submodules. ([GitHub][2])

[1]: https://github.com/microsoft/pyright/issues/9393?utm_source=chatgpt.com "google.cloud.storage reports Stub file not found for \"google.cloud.storage\" (reportMissingTypeStubs) · Issue #9393 · microsoft/pyright · GitHub"
[2]: https://github.com/microsoft/pylance-release/issues/1687?utm_source=chatgpt.com "Missing imports for many `google.cloud` libraries · Issue googleapis/python-storage#1687 · microsoft/pylance-release · GitHub"

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.