googleapis / googleapis/google-cloud-python
Missing type annotations (py.typed/stubs) for google.cloud.storage causing Pylance/Pyright complaints
- Ngôn ngữ chính
- Python
- Star
- 5.4k
- Fork
- 1.8k
- Merge trung bình
- 3 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 122
Mô tả
#### 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"
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.