Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation stacklevels #4203

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)