Correct stacklevel for check_deprecated_parameters (#4203)

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Aarni Koskela 2023-05-15 15:22:16 +03:00 committed by GitHub
parent 4e4549c063
commit 2f2123b5ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -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:

View File

@ -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):
"""

View File

@ -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,
)