Skip to content

Consider adding py.typed to repo to support type checking #4654

@acciaioli

Description

@acciaioli

Is your feature request related to a problem? Please describe.
Despite being typed, this package doesnt include a py.typed file.
As a user, i am struggling to benefit from the defined types

Consider the code featured in the quickstart page

import vertexai
from vertexai.generative_models import GenerativeModel

# TODO(developer): Update and un-comment below line
PROJECT_ID = "your-project-id"
vertexai.init(project=PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.5-flash-002")
reveal_type(model)
response = model.generate_content(
    "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
)
reveal_type(response)
print(response.text)
►mypy
scripts/gc_sdk.py:1: error: Skipping analyzing "vertexai": module is installed, but missing library stubs or py.typed marker  [import-untyped]
scripts/gc_sdk.py:2: error: Skipping analyzing "vertexai.generative_models": module is installed, but missing library stubs or py.typed marker  [import-untyped]
scripts/gc_sdk.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
scripts/gc_sdk.py:9: note: Revealed type is "Any"
scripts/gc_sdk.py:13: note: Revealed type is "Any"

And if I add the py.typed manually..

►mypy
scripts/gc_sdk.py:9: note: Revealed type is "vertexai.generative_models._generative_models.GenerativeModel"
scripts/gc_sdk.py:13: note: Revealed type is "vertexai.generative_models._generative_models.GenerationResponse"
Found 2 errors in 1 file (checked 48 source files)

This would help find issues using the lib, for example:

model = GenerativeModel("gemini-1.5-flash", version="002") 
scripts/gc_sdk.py:8: error: Unexpected keyword argument "version" for "GenerativeModel"  [call-arg]

Describe the solution you'd like
I would like you to consider adding a empty file py.typed inside the vertexai directory

Describe alternatives you've considered
I am considering creating the py.typed just before I ran mypy in my CI
This way, I could use this lib with type safety

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: vertex-aiIssues related to the googleapis/python-aiplatform API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions