From 2baf33c33fd03d48adb589f5625f0dfe9525eae1 Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Wed, 28 Jun 2023 15:02:01 -0400 Subject: [PATCH] Fix Wrong Deprecation Warning message for type/plot parameter (#4709) * Add code * CHANGELOG * Fix * Add to changelog --- CHANGELOG.md | 2 ++ gradio/deprecation.py | 9 +++++++-- test/test_components.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53b55196e9..d910502797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - Fix double upload bug that caused lag in file uploads by [@aliabid94](https://github.com/aliabid94) in [PR 4661](https://github.com/gradio-app/gradio/pull/4661) - `Progress` component now appears even when no `iterable` is specified in `tqdm` constructor by [@itrushkin](https://github.com/itrushkin) in [PR 4475](https://github.com/gradio-app/gradio/pull/4475) - Deprecation warnings now point at the user code using those deprecated features, instead of Gradio internals, by (https://github.com/akx) in [PR 4694](https://github.com/gradio-app/gradio/pull/4694) +- The `plot` parameter deprecation warnings should now only be emitted for `Image` components by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4709](https://github.com/gradio-app/gradio/pull/4709) +- Removed uncessessary `type` deprecation warning by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4709](https://github.com/gradio-app/gradio/pull/4709) - Ensure Audio autoplays works when `autoplay=True` and the video source is dynamically updated [@pngwn](https://github.com/pngwn) in [PR 4705](https://github.com/gradio-app/gradio/pull/4705) diff --git a/gradio/deprecation.py b/gradio/deprecation.py index f9283df454..d14f88ffcd 100644 --- a/gradio/deprecation.py +++ b/gradio/deprecation.py @@ -11,6 +11,10 @@ class GradioDeprecationWarning(UserWarning): pass +class GradioUnusedKwargWarning(UserWarning): + pass + + def simple_deprecated_notice(term: str) -> str: return f"`{term}` parameter is deprecated, and it has no effect" @@ -38,7 +42,6 @@ DEPRECATION_MESSAGE = { "width": use_in_launch("width"), "height": use_in_launch("height"), "plot": "The 'plot' parameter has been deprecated. Use the new Plot component instead", - "type": "The 'type' parameter has been deprecated. Use the Number component instead.", } @@ -50,13 +53,15 @@ def check_deprecated_parameters( for key, value in DEPRECATION_MESSAGE.items(): if key in kwargs: + if key == "plot" and cls != "Image": + continue kwargs.pop(key) warnings.warn(value, GradioDeprecationWarning, stacklevel=stacklevel) if kwargs: warnings.warn( f"You have unused kwarg parameters in {cls}, please remove them: {kwargs}", - GradioDeprecationWarning, + GradioUnusedKwargWarning, stacklevel=stacklevel, ) diff --git a/test/test_components.py b/test/test_components.py index 22f5000ac2..24b880b00e 100644 --- a/test/test_components.py +++ b/test/test_components.py @@ -26,6 +26,10 @@ from scipy.io import wavfile import gradio as gr from gradio import processing_utils, utils +from gradio.deprecation import ( + GradioDeprecationWarning, + GradioUnusedKwargWarning, +) os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" @@ -2891,3 +2895,16 @@ class TestTempFileManagement: f = temp_file_manager.download_temp_copy_if_needed(url2) assert len(temp_file_manager.temp_files) == 2 + + +def test_type_arg_deperecation_warning(): + with pytest.warns(GradioUnusedKwargWarning): + gr.Video(type="filepath") + + +def test_plot_arg_deprecation_warning(): + with pytest.warns(GradioDeprecationWarning): + gr.Image(plot=True) + + with pytest.warns(GradioUnusedKwargWarning): + gr.File(plot=True)