fix insufficient typing of event listeners (#8983)

This commit is contained in:
JackismyShephard 2024-08-05 19:13:43 +02:00 committed by GitHub
parent 3feea64a65
commit 4365237599
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 4 deletions

View File

@ -1295,7 +1295,7 @@ class Blocks(BlockContext, BlocksEvents, metaclass=BlocksMeta):
for block in self.blocks.values()
)
def unload(self, fn: Callable):
def unload(self, fn: Callable[..., Any]) -> None:
"""This listener is triggered when the user closes or refreshes the tab, ending the user session.
It is useful for cleaning up resources when the app is closed.
Parameters:

View File

@ -14,10 +14,12 @@ from gradio.utils import no_raise_exception
INTERFACE_TEMPLATE = '''
{{ contents }}
from typing import Callable, Literal
from gradio.blocks import Block
{% for event in events %}
def {{ event }}(self,
fn: Callable | None = None,
fn: Callable[..., Any] | None = None,
inputs: Block | Sequence[Block] | set[Block] | None = None,
outputs: Block | Sequence[Block] | None = None,
api_name: str | None | Literal[False] = None,

View File

@ -986,8 +986,8 @@ def update(
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
visible: bool | None = None,
**kwargs,
) -> dict:
**kwargs: Any,
) -> dict[str, Any]:
"""
Updates a component's properties. When a function passed into a Gradio Interface or a Blocks events returns a value, it typically updates the value of the output component. But it is also possible to update the *properties* of an output component (such as the number of lines of a `Textbox` or the visibility of an `Row`) by returning a component and passing in the parameters to update in the constructor of the component. Alternatively, you can return `gr.update(...)` with any arbitrary parameters to update. (This is useful as a shorthand or if the same function can be called with different components to update.)