Feat/static type stubs without engine files#34
Open
adarshdigievo wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds generated static typing stub files (.pyi) for the serpapi package, plus helper scripts under typing/ to regenerate those stubs from SerpApi engine metadata, and packaging/CI updates so the stubs are distributed with releases.
Changes:
- Add a stub generator (
typing/generate_type_stubs.py) and an engine-metadata fetcher (typing/build-engines.py). - Check in generated typing artifacts under
serpapi/(stub files +py.typed) and include them in sdist/wheel packaging. - Add a release workflow step intended to verify stub generation consistency.
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| typing/generate_type_stubs.py | New generator that builds .pyi stubs from engine JSON metadata. |
| typing/build-engines.py | New script that fetches SerpApi playground metadata and writes engine JSON files locally. |
| tests/test_build_typing.py | Tests for stub generation helpers (syntax validation, output structure). |
| serpapi/py.typed | PEP 561 marker for distributing typing information. |
| serpapi/init.pyi | Generated top-level stub exports for the package API. |
| pyproject.toml | Adds typing_extensions runtime dep; adds dev extra; configures package data for .pyi/py.typed. |
| MANIFEST.in | Ensures stub files are included in source distributions. |
| .github/workflows/release.yml | Adds a --check step intended to verify generated typing files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import tempfile | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import Any, Iterable |
| return unique | ||
|
|
||
|
|
||
| def literal_type(values: list[Any]) -> str | None: |
| return f"{prefix}JsonSearchParams", f"{prefix}HtmlSearchParams" | ||
|
|
||
|
|
||
| def format_typed_dict(engine: Engine, *, class_name: str, output: Param | None = None) -> list[str]: |
|
|
||
| def format_search_overload( | ||
| *, | ||
| receiver: str | None, |
|
|
||
| def format_params_dict_overload( | ||
| *, | ||
| receiver: str | None, |
| return lines | ||
|
|
||
|
|
||
| def format_params_dict_overloads(*, receiver: str | None, engine: Engine) -> list[str]: |
| return lines | ||
|
|
||
|
|
||
| def format_search_overloads(engines: list[Engine], *, receiver: str | None) -> list[str]: |
| return parser.parse_args(argv) | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: |
Comment on lines
50
to
54
| - name: Build sdist and wheel | ||
| run: | | ||
| pip install build | ||
| python typing/generate_type_stubs.py --check | ||
| python -m build |
| [project.optional-dependencies] | ||
| color = ["pygments"] | ||
| test = ["pytest"] | ||
| dev = ["markdownify"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
devdependencies (pip install -e ".[dev]"), generate engine files by running:python typing/build_engines.pypython typing/generate_type_stubs.pyto auto-generate.pyitype stub files.