2
0
mirror of https://github.com/gradio-app/gradio.git synced 2025-04-18 12:50:30 +08:00

fix avoid in-place dict updates ()

* fix  avoid in-place dict updates

* add tests and changelog for PR3405
This commit is contained in:
gitgithan 2023-03-08 02:12:19 +08:00 committed by GitHub
parent fddf376784
commit ee1a76fd10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 836 additions and 653 deletions

1
.gitignore vendored

@ -40,6 +40,7 @@ demo/*/config.json
# Etc
.idea/*
.vscode/*
.DS_Store
*.bak
workspace.code-workspace

File diff suppressed because it is too large Load Diff

@ -251,6 +251,7 @@ class Block:
@classmethod
def get_specific_update(cls, generic_update: Dict[str, Any]) -> Dict:
generic_update = generic_update.copy()
del generic_update["__type__"]
specific_update = cls.update(**generic_update)
return specific_update

@ -484,6 +484,22 @@ class TestBlocksPostprocessing:
output = demo.postprocess_data(0, gr.update(value="NO_VALUE"), state={})
assert output[0]["value"] == "NO_VALUE"
def test_blocks_does_not_del_dict_keys_inplace(self):
with gr.Blocks() as demo:
im_list = [gr.Image() for i in range(2)]
def change_visibility(value):
return [gr.update(visible=value)] * 2
checkbox = gr.Checkbox(value=True, label="Show image")
checkbox.change(change_visibility, inputs=checkbox, outputs=im_list)
output = demo.postprocess_data(0, [gr.update(visible=False)] * 2, state={})
assert output == [
{"visible": False, "__type__": "update"},
{"visible": False, "__type__": "update"},
]
def test_blocks_returns_correct_output_dict_single_key(self):
with gr.Blocks() as demo:
num = gr.Number()