Repository navigation
Give implements a return type, so checkers see typed widget calls - #81
Merged
Merged
Conversation
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>
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.
Type checkers now see the real element type of every widget call that reacton and ipyvuetify build with
implements.Problem
reacton.utils.implementshas no return annotation. ty does not infer the return type of a function in an installed package. So every function built withimplementsreturnsAnyorUnknownto its users. That covers all ofipyvuetify.componentsandreacton.ipywidgets. A call such assolara.v.Btn(...)is therefore never checked, and a typo in an argument or a wrong use of the result goes unnoticed.Change
implementsnow declares that it returnsCallable[[Callable], Callable[P, T]]. This is what the innercasteralready returned. Runtime behavior does not change.Validation
solara.v.Btn(children=["x"])wasUnknown. After the change, it isValueElement[Btn, Any], andsolara.v.Html(tag="div")isValueElement[Html, Any].reacton/utils.pygives the same twotype-varerrors as on master, inwrapandgenerate.py. This change adds none.Bug found
The new type already found a bug.
reacton/utils_test.pycalledw.Button(on_click=..., label=...), but ipywidgetsButtonhas nolabelargument. The text argument isdescription. The test only checks equality, so it passed at runtime. mypy in CI now flagged it, and the second commit fixes the test.Gaps
solara.Button(...)staysUnknown. A separate solara PR will fix that.Align results
Caution
/alignwas not run on this change: it is a one-line annotation that matches the existing runtime behavior.Crossreview results
Caution
/crossreviewwas not run on this change: it is a one-line annotation, a small mechanical fix.🤖 Generated with Claude Code