Skip to content

Commit

Permalink
[Deprecate] Correct stacklevel (huggingface#1483)
Browse files Browse the repository at this point in the history
* Correct stacklevel

* fix
  • Loading branch information
patrickvonplaten authored and Thomas Capelle committed Dec 12, 2022
1 parent 40c0865 commit 5ffefe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/diffusers/utils/deprecation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def deprecate(*args, take_from: Optional[Union[Dict, Any]] = None, standard_warn

if warning is not None:
warning = warning + " " if standard_warn else ""
warnings.warn(warning + message, FutureWarning)
warnings.warn(warning + message, FutureWarning, stacklevel=2)

if isinstance(deprecated_kwargs, dict) and len(deprecated_kwargs) > 0:
call_frame = inspect.getouterframes(inspect.currentframe())[1]
Expand Down
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,9 @@ def test_deprecate_incorrect_no_standard_warn(self):
deprecate(("deprecated_arg", self.higher_version, "This message is better!!!"), standard_warn=False)

assert str(warning.warning) == "This message is better!!!"

def test_deprecate_stacklevel(self):
with self.assertWarns(FutureWarning) as warning:
deprecate(("deprecated_arg", self.higher_version, "This message is better!!!"), standard_warn=False)
assert str(warning.warning) == "This message is better!!!"
assert "diffusers/tests/test_utils.py" in warning.filename

0 comments on commit 5ffefe8

Please sign in to comment.