Skip to content

stagehand-python@4.2.0a0.dev1526

@github-actions github-actions tagged this 19 Sep 21:04
Mirrored from external contributor PR #2987 after approval by
@miguelg719.

Original author: @antonvishal
Original PR: https://github.com/browserbase/stagehand/pull/2987
Approved source head SHA: `ff8d7771e96c597b1adbcf7819fbe179b84d640a`

@antonvishal, please continue any follow-up discussion on this mirrored
PR. When the external PR gets new commits, this same internal PR will be
marked stale until the latest external commit is approved and refreshed
here.

## Original description
## Why

The Python SDK excluded generated models from ty, leaving
schema-to-Python typing errors undetected. Upgrading to ty 0.0.82 also
exposed type errors in Chrome process handling. Since generated models
ship as part of the typed SDK, these issues can affect downstream type
checking.

## What

- Upgrade and pin ty to 0.0.82, include generated Python in its checks,
and enable selected stricter rules.
- Generate validated model factories for dictionary defaults typed as
Pydantic models. The generator detects these fields automatically, while
leaving ordinary dictionary defaults alone.
- Fix the Chrome process and return-type diagnostics, add required
`@override` decorators, and run ty immediately after Python generation.
- Add tests for generated defaults and for the generator’s model-field
detection.

## How

Verified with `generate.py --check`, ty, Ruff, the Python test suite
(531 passed, 1 skipped), and `just check`.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Starts type-checking generated Python SDK models and upgrades and pins
`ty` to 0.0.82. The generated models were previously excluded from `ty`,
so schema-to-Python typing errors went undetected and could affect
downstream type checking.

- Enables stricter `ty` rules for override enforcement and return
handling.
- Rewrites Pydantic-typed dictionary defaults in generated code as model
factories so defaults keep their declared types and wire values; plain
dict defaults are unchanged.
- Fixes the Chrome process and return-type diagnostics exposed by the
stricter rules.
- Adds required `@override` decorators and `typing_extensions` as a
runtime dependency.
- Runs `ty` as part of `just generate`.
- Adds tests for generated defaults and the generator’s model-field
detection.

<sup>Written for commit ff8d7771e96c597b1adbcf7819fbe179b84d640a.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2987?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

<!-- external-contributor-pr:owned source-pr=2987
source-sha=ff8d7771e96c597b1adbcf7819fbe179b84d640a claimer=miguelg719
-->

Co-authored-by: Vishal Anton <vishalanton@appexert.com>
Co-authored-by: VIshal Anton <166398166+antonvishal@users.noreply.github.com>
Assets 2
Loading