From 2f2123b5acfd847ce566516309bec9287f6c335a Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 15 May 2023 15:22:16 +0300 Subject: [PATCH] Correct stacklevel for check_deprecated_parameters (#4203) Co-authored-by: Abubakar Abid --- CHANGELOG.md | 1 + gradio/blocks.py | 4 +++- gradio/deprecation.py | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86386c78ae..d5d746dad7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ## Bug Fixes: +- 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). - Fix "TypeError: issubclass() arg 1 must be a class" When use Optional[Types] by [@lingfengchencn](https://github.com/lingfengchencn) in [PR 4200](https://github.com/gradio-app/gradio/pull/4200). ## Other Changes: diff --git a/gradio/blocks.py b/gradio/blocks.py index 72b37b4e30..193ed35c64 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -96,7 +96,9 @@ class Block: 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 555a4fed44..15d0156790 100644 --- a/gradio/deprecation.py +++ b/gradio/deprecation.py @@ -32,14 +32,15 @@ DEPRECATION_MESSAGE = { } -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, )