Skip to content

Give implements a return type, so checkers see typed widget calls - #81

Merged
maartenbreddels merged 2 commits into
masterfrom
maarten/type-implements
Oct 23, 2026
Merged

maartenbreddels merged 2 commits into
masterfrom
maarten/type-implements

Conversation

@maartenbreddels

@maartenbreddels maartenbreddels commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Type checkers now see the real element type of every widget call that reacton and ipyvuetify build with implements.

Problem

reacton.utils.implements has no return annotation. ty does not infer the return type of a function in an installed package. So every function built with implements returns Any or Unknown to its users. That covers all of ipyvuetify.components and reacton.ipywidgets. A call such as solara.v.Btn(...) is therefore never checked, and a typo in an argument or a wrong use of the result goes unnoticed.

Change

implements now declares that it returns Callable[[Callable], Callable[P, T]]. This is what the inner caster already returned. Runtime behavior does not change.

Validation

  • I ran ty 0.0.56 on a small probe file. Before the change, solara.v.Btn(children=["x"]) was Unknown. After the change, it is ValueElement[Btn, Any], and solara.v.Html(tag="div") is ValueElement[Html, Any].
  • I ran ty over the GrottoAI leasing app, which uses solara and ipyvuetify heavily, with this change installed. It still passes with no new errors.
  • mypy on reacton/utils.py gives the same two type-var errors as on master, in wrap and generate.py. This change adds none.

Bug found

The new type already found a bug. reacton/utils_test.py called w.Button(on_click=..., label=...), but ipywidgets Button has no label argument. The text argument is description. The test only checks equality, so it passed at runtime. mypy in CI now flagged it, and the second commit fixes the test.

Gaps

  • Most solara components also lack a return annotation, so solara.Button(...) stays Unknown. A separate solara PR will fix that.
  • I did not run the reacton test suite. The change is an annotation only.

Align results

Caution

/align was not run on this change: it is a one-line annotation that matches the existing runtime behavior.

Crossreview results

Caution

/crossreview was not run on this change: it is a one-line annotation, a small mechanical fix.

🤖 Generated with Claude Code

maartenbreddels and others added 2 commits October 23, 2026 14:11
implements() had no return annotation. ty does not infer return types
of installed packages, so every function built with it, such as all of
ipyvuetify.components and reacton.ipywidgets, returned Any or Unknown.
A call like solara.v.Btn(...) was therefore never checked.

With the annotation, ty reveals solara.v.Btn(...) as
ValueElement[Btn, Any]. A ty run over the GrottoAI leasing app with this
change still passes. mypy gives the same two errors as on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With implements typed, mypy now checks the arguments of w.Button. The
test passed label=..., but ipywidgets Button has no label argument, so
the element held a keyword the widget never uses. The test only checks
equality, so it passed at runtime. description is the argument that
sets the button text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maartenbreddels
maartenbreddels marked this pull request as ready for review October 23, 2026 12:48
@maartenbreddels
maartenbreddels merged commit efbb63c into master Oct 23, 2026
24 checks passed
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.

1 participant