mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
Correct stacklevel for check_deprecated_parameters (#4203)
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
4e4549c063
commit
2f2123b5ac
@ -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:
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user