Skip to content

Type-check all Python with ty and standard Ruff rules - #4647

Merged
max-sixty merged 4 commits into
mainfrom
python-lints-types
Oct 29, 2026
Merged

max-sixty merged 4 commits into
mainfrom
python-lints-types

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Leaf had no Python type-check gate. Add ty to the developer environment and pre-commit so the existing CI and local landing gates check all 573 tracked Python files, including developer tools, tests, hooks, bundled scripts and the website adapter.

Match numbagg's standard Ruff families (F, E, W, I, UP) and its formatter-compatible exceptions. Fix the discovered types throughout the tree: accurate shared protocols and container types, optional-value preconditions, callback signatures, and narrow test-double boundaries. Preserve the existing serving fixture's callable identity and runtime behavior. There is no diagnostic baseline or directory-wide type suppression; the few local type ignores describe dependency typing gaps and a cross-thread observation.

The shared browser fixture also unregisters pending page and context routes before closing them. A controlled cancellation reproduces the disposed-response exception leaking into the next test; Playwright's native route cleanup prevents it while preserving errors during a live test.

Validation: whole-tree ty, Ruff lint/format, full pre-commit, and pnpm run check pass. Focused tests passed across the source/Codex model (105), website/bridge (100), developer tools (53), Markdown rendering (42), and shared test fixtures (57). Independent implementation and fixture reviews found no remaining issues.

Inherited product-test failures were checked against the unchanged base commit: all six failing render-corpus cases (code-comparison, dynamic-widgets, notification-playground, ship-review, thread-panel-gallery, feature-gallery), the sampled focus-ring failure, and feature-gallery's unchanged disabled-property write reproduce with the same causes. The margin-group and folded-panel passive-shift failures also appear in the earlier main CI run. The baseline comparison finished with seven failures and one teardown error; these are inherited under the repository's test policy.

One additional developer preview subscription test has an inherited assertion failure: the candidate and the original implementation produce the same watch roots. Developer-tool tests are outside CI's product selection.

This was written by Codex on behalf of max-sixty

Run whole-tree ty through pre-commit and its existing CI gate. Match the standard F/E/W/I/UP Ruff families, including import sorting and modern Python syntax.

Correct shared protocols, optional-value preconditions, heterogeneous containers, callback signatures and deliberate test-double injection boundaries across the application, developer tools, packaged scripts and tests. Keep the existing runtime behavior and callable fixture identity.
leaf-agent
leaf-agent previously approved these changes Oct 28, 2026

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Local validation found failures that reproduce on main at ed2bc25, so they do not withhold this approval:

  • In the response-time tests, test_query_keeps_input_identity_and_missing_observations and test_query_reports_clock_errors_and_requires_qualified_timestamps expect summaries without the existing total_s field.
  • In the App Server tests, test_app_server_observer_connects_over_a_private_unix_socket and test_codex_launch_owns_one_private_app_server hit this sandbox's unsupported AF_UNIX sockets (Errno 97). A direct socket creation fails too. I interrupted the larger selection after that limitation recurred; its remaining tests are unverified.

…ecking

Keep absent lifecycles and bare-shell harnesses valid, retain the no-session hook no-op, and distinguish an omitted stop owner from explicit None. Let the browser fixture own page cleanup.
Keep the session-phase helpers main introduced while retaining the type fixes. Unregister page and context routes with Playwright ignoreErrors after health checks and before context close, so cancellation cannot leak a disposed-response exception into the next test.
@max-sixty
max-sixty merged commit 71816cf into main Oct 29, 2026
3 of 4 checks passed
@max-sixty
max-sixty deleted the python-lints-types branch October 29, 2026 01:31
max-sixty added a commit that referenced this pull request Oct 30, 2026
…ate capture as a Generator

#4686 launched stills' browser with ignore_default_args, which the test's
headless_shell stand-in refused, so all three stills tests failed on main.
ty (#4647) asks a @contextmanager to return Generator.
max-sixty added a commit that referenced this pull request Oct 30, 2026
…ev stills (#4713)

`leaf-dev stills` now says which rule is behind each computed-style
difference it reports. Under the grouped differences in `styles.txt`, it
takes each group's first element and lists the declarations that match
it in only one arm, or in a different order, each labelled with its
sheet, `@layer`, `@scope` and selector. The declarations come from
Chrome's DevTools protocol (`CSS.getMatchedStylesForNode`). Two of the
sessions surveyed for #4648 wrote this lookup by hand to find a cause.

## What it shows

Replayed against #4637's base (`leaf-dev stills ae2e3f3 --state
on-me`, about 2 minutes), it names both causes that session found by
hand:

```
html
    + theme.css @layer lf-base :where(:root) { color: revert; }
    + theme.css @layer lf-base :where(:root) { font-family: revert; }
…lf-options#ar-3ds-choice > form.lf-another.lf-ui
    + theme.css @layer lf-base lf-options:has(> lf-option > strong) > .lf-another { font: inherit; }
```

It also names a later commit's `:nth-child(1 of :not(.lf-ui,
[data-lf-gen])) { margin-block-start: 0 }` behind a paragraph's margin
change. Where an element's declarations match on both arms, such as the
hidden-widget noise, it says `none: it inherits the difference or reads
it from a custom property`. A separate probe read an element inside
lf-diff's shadow tree on pr-walkthrough, which is where the `.lf-ui`
reorder regression appeared.

## Design

- **Declarations, not a winner.** Naming the declaration that wins would
take part of the cascade. Shorthands such as `font: var(...)` leave
their longhands blank in the protocol, and on top of that it would need
logical properties, `!important` across layers, and shadow-tree
ordering. Listing what changed, in the protocol's order, avoids all of
that, and the reader infers the winner. A declaration that moved shows
as a `-` line and a `+` line with the same text.
- **Labels stable across arms.** The labels use a sheet's file name, or
`constructed`, `<style>` or `user-agent`. Never a URL, since an inline
sheet's URL is its document's and includes the arm's port.
- **Both arms stay open.** `capture` is now a context manager, so the
comparison can read both tabs after `style_changes` has found which
elements differ.

## Also here

`main`'s stills tests have failed since #4686, which launches the
browser with `ignore_default_args`; the test's stand-in for
`headless_shell` now accepts launch options. `capture` is annotated as a
`Generator`, as ty (#4647) asks.

> _This was written by Claude Code on behalf of max-sixty_
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