Skip to content

Commit

Permalink
Correct stacklevel for check_deprecated_parameters (gradio-app#4203)
Browse files Browse the repository at this point in the history
Co-authored-by: Abubakar Abid <[email protected]>
  • Loading branch information
akx and abidlabs authored May 15, 2023
1 parent 4e4549c commit 2f2123b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ 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):
"""
Expand Down
9 changes: 5 additions & 4 deletions gradio/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 2f2123b

Please sign in to comment.