Skip to content

Feat/static type stubs without engine files#34

Open
adarshdigievo wants to merge 2 commits into
masterfrom
feat/static-type-stubs-without-engines
Open

Feat/static type stubs without engine files#34
adarshdigievo wants to merge 2 commits into
masterfrom
feat/static-type-stubs-without-engines

Conversation

@adarshdigievo

Copy link
Copy Markdown
Member
  • Alternative to Add static type checking support using .pyi stub files #33, this one omits committing engine files to git.
  • Steps for generating type stubs (.pyi files):
    1. After installing dev dependencies (pip install -e ".[dev]"), generate engine files by running: python typing/build_engines.py
    2. Once engine files are created, run python typing/generate_type_stubs.py to auto-generate .pyi type stub files.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment thread pyproject.toml
[project.optional-dependencies]
color = ["pygments"]
test = ["pytest"]
dev = ["markdownify"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants