Skip to content

Commit

Permalink
Improve traceback message
Browse files Browse the repository at this point in the history
  • Loading branch information
viljarjf committed Nov 7, 2024
1 parent bcd687f commit 6edc0b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/instamatic/TEMController/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
warnings.warn(
'The `TEMController` module is deprecated since version 2.0.6. Use the `controller`-module instead',
VisibleDeprecationWarning,
stacklevel=2,
)


Expand Down
8 changes: 5 additions & 3 deletions src/instamatic/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from __future__ import annotations


class VisibleDeprecationWarning(UserWarning):
"""
Numpy-inspired deprecation warning which will be shown by default.
"""Numpy-inspired deprecation warning which will be shown by default.
The default `DeprecationWarning` does not show by default.
"""


def deprecated(since: str, alternative: str, removed: str = None):
"""Mark a function as deprecated, printing a warning whenever it is used.
Expand All @@ -34,7 +36,7 @@ def wrapped(*args, **kwargs):
msg = f'Function {func.__name__} is deprecated since {since}, use {alternative} instead.'
if removed is not None:
msg += f' Will be removed in version {removed}.'
warnings.warn(msg, VisibleDeprecationWarning)
warnings.warn(msg, VisibleDeprecationWarning, stacklevel=2)
return func(*args, **kwargs)

return wrapped
Expand Down

0 comments on commit 6edc0b3

Please sign in to comment.