From 053e213266ea3c3bf8b3e3f05beb80bd3cf36ad5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sat, 13 May 2023 18:18:49 +0300 Subject: [PATCH] Correct stacklevel for check_deprecated_parameters --- CHANGELOG.md | 2 +- gradio/blocks.py | 2 +- gradio/deprecation.py | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e84a45eafa4c..5925568082f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ No changes to highlight. ## Bug Fixes: -No changes to highlight. +- The deprecation warnings for kwargs now show the actual stack level for the invocation, by [@akx](https://github.com/akx) in [PR 4203](https://github.com/gradio-app/gradio/pull/4203). ## Other Changes: diff --git a/gradio/blocks.py b/gradio/blocks.py index 72b37b4e305d5..b62ece1e65b4a 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -96,7 +96,7 @@ def __init__( if render: self.render() - check_deprecated_parameters(self.__class__.__name__, **kwargs) + check_deprecated_parameters(self.__class__.__name__, stacklevel=6, kwargs=kwargs) def render(self): """ diff --git a/gradio/deprecation.py b/gradio/deprecation.py index 555a4fed4474e..15d015679039b 100644 --- a/gradio/deprecation.py +++ b/gradio/deprecation.py @@ -32,14 +32,15 @@ def use_in_launch(term: str) -> str: } -def check_deprecated_parameters(cls: str, **kwargs) -> None: +def check_deprecated_parameters(cls: str, *, stacklevel: int = 2, kwargs) -> None: for key, value in DEPRECATION_MESSAGE.items(): if key in kwargs: kwargs.pop(key) # Interestingly, using DeprecationWarning causes warning to not appear. - warnings.warn(value) + warnings.warn(value, stacklevel=stacklevel) - if len(kwargs) != 0: + if kwargs: warnings.warn( - f"You have unused kwarg parameters in {cls}, please remove them: {kwargs}" + f"You have unused kwarg parameters in {cls}, please remove them: {kwargs}", + stacklevel=stacklevel, )