mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
* Fixes #9742 Validator was not handling situation where function does not return anything. Signed-off-by: Richard Decal <public@richarddecal.com> * add test case for function which doesn't return anything Signed-off-by: Richard Decal <public@richarddecal.com> * format * add changeset --------- Signed-off-by: Richard Decal <public@richarddecal.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
80c1c664c9
commit
16895e8628
5
.changeset/happy-lies-study.md
Normal file
5
.changeset/happy-lies-study.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fixes #9742
|
@ -1744,6 +1744,10 @@ Received inputs:
|
||||
[{received}]"""
|
||||
)
|
||||
else:
|
||||
if len(predictions) == 1 and predictions[0] is None:
|
||||
# do not throw error if the function did not return anything
|
||||
# https://github.com/gradio-app/gradio/issues/9742
|
||||
return
|
||||
warnings.warn(
|
||||
f"""A function{name} returned too many output values (needed: {len(dep_outputs)}, returned: {len(predictions)}). Ignoring extra values.
|
||||
Output components:
|
||||
|
@ -8,6 +8,7 @@ import random
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
import warnings
|
||||
from concurrent.futures import wait
|
||||
from contextlib import contextmanager
|
||||
from functools import partial
|
||||
@ -703,6 +704,26 @@ class TestBlocksPostprocessing:
|
||||
demo.fns[0], predictions=["test", "test2", "test3"], state=None
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_warning_if_func_has_no_outputs(self):
|
||||
"""
|
||||
Ensures that if a function has no outputs, no warning is raised.
|
||||
"""
|
||||
with gr.Blocks() as demo:
|
||||
button = gr.Button()
|
||||
|
||||
def no_return():
|
||||
pass
|
||||
|
||||
button.click(
|
||||
no_return,
|
||||
inputs=None,
|
||||
outputs=None,
|
||||
)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
await demo.postprocess_data(demo.fns[0], predictions=None, state=None) # type: ignore
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_error_raised_if_num_outputs_mismatch_with_function_name(self):
|
||||
def infer(x):
|
||||
|
Loading…
x
Reference in New Issue
Block a user