Skip to content

Commit

Permalink
Correct stacklevel for check_deprecated_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed May 13, 2023
1 parent 83134c1 commit 053e213
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ No changes to highlight.

## Bug Fixes:

No changes to highlight.
- 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).

## Other Changes:

Expand Down
2 changes: 1 addition & 1 deletion gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ 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 053e213

Please sign in to comment.