-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix type hints for render and on #8429
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/1c535500afa038b9170e18d9e806883323b7b2ba/gradio-4.32.2-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@1c535500afa038b9170e18d9e806883323b7b2ba#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/1c535500afa038b9170e18d9e806883323b7b2ba/gradio-client-0.20.1.tgz |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
inputs: list[Component] | None = None, | ||
triggers: list[EventListener] | EventListener | None = None, | ||
inputs: list[Component] | Component | None = None, | ||
triggers: Sequence[EventListenerCallable] | EventListenerCallable | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only issue with putting Sequence
here is that it'll affect the docs for gr.render(): https://www.gradio.app/docs/gradio/render
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think many Python users don't know what Sequence
is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a step in the docs generation to convert Sequence
container types to list
@aliabd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can edit 01_render.svx
to do this but maybe we do this once users complain? I would prefer to not introduce a difference between docs and code unless it's absolutely necessary imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think this would be applicable in many other parts of the codebase as well (e.g. anywhere we currently type hint list[Component]
should really be Sequence[Component]
) so I don't think we should manually edit but doing it later is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think we can edit the ParamTable svelte component in that case but will hold off for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I was trying to see if we could actually use EventListenerCallable to typehint EventListener.listener, so that if EventListenerCallable ever diverges from the actual signature of a listener, our typecheker catches it. Cou;dn't figure it out though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the reviews everyone! |
Description
I noticed two things that were off about the type hints for on and render
Any
for the triggers ofgr.on
. Which was too broad.render
, the triggers were not typed correctly so passing a valid trigger, e.g.slider.change
would be flagged in vs code.render
, the type hint did not allow for a single component to be passed as input, but it is allowed.Main
PR
Invalid value for
triggers
ofgr.on
is flaggedPassing an event listener method for
render
is not flagged🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh